how to tune BufferedInputStream read()?

Posted by technomax on Stack Overflow See other posts from Stack Overflow or by technomax
Published on 2010-04-02T07:37:29Z Indexed on 2010/04/02 7:43 UTC
Read the original article Hit count: 156

Filed under:
|

I am reading a BLOB column from a Oracle database, then writing it to a file as follows:

    public static int execute(String filename, BLOB blob)
  {

    int success = 1;

    try
    {
      File              blobFile   = new File(filename);
      FileOutputStream  outStream  = new FileOutputStream(blobFile);
      BufferedInputStream inStream   = new BufferedInputStream(blob.getBinaryStream());

      int     length  = -1;
      int     size    = blob.getBufferSize();
      byte[]  buffer  = new byte[size];

      while ((length = inStream.read(buffer)) != -1)
      {
        outStream.write(buffer, 0, length);
        outStream.flush();
      }

      inStream.close();
      outStream.close();
    }
    catch (Exception e)
    {
      e.printStackTrace();
      System.out.println("ERROR(img_exportBlob) Unable to export:"+filename);
      success = 0;
    }
}

The file size is around 3MB and it takes 40-50s to read the buffer. Its actually a 3D image data. So, is there any way by which I can reduce this time?

© Stack Overflow or respective owner

Related posts about bufferedinputstream

Related posts about java