Subject Re: BLOB SUB_TYPE 1
Author robert_difalco
>
> Also if you want to have more generic solution, try to stick to
> setBytes(byte[]), setBinaryStream(InputStream) and
> setCharacterStream(Reader).
>

Yeah, that is what I was using, but I was trying to workaround some
performance inconsistencies in those methods (including #setString()).

Even if I provide fixes for the latest source, I need something that
will work with the currently released binaries. So, for my project
this is much faster:

byte[] blobBytes = ...;

Blob blob = c.createBlob();
OutputStream out = blob.setBinaryStream( 0 );
try
{
out.write( blobBytes, 0, blobBytes.length );
}
finally
{
out.close();
}

ps.setBlob( COLUMN_BLOB, blob );

This is much faster than the following:

ps.setBytes( COLUMN_BLOB, blobBytes );

In the current code, the calle to #setBytes will create a
ByteArrayInputStream around "blobBytes", which calls
FBBlob#copyStream. This method then creates a new byte array of size
bufferlength which is often 16*1024 bytes in length. This buffer is
created even if you are only writing a few bytes. Then this method
calls FBBlobOutputStream#write, which creates yet another 16*1024
sized buffer. And it gets worse. If the bytes sent to
FBBlobOutputStream#write is less than "bufferlength", then TWO buffers
are created. One of 16*1024 that is NEVER even used, and another that
is the same size as the input bytes, which the input bytes are then
copied into before finally being sent to the database server.

This happens for every call to #setBytes, #setString,
#setBinaryStream, etc. So you can see why (at least for the current
version of the driver), I was trying to avoid those calls.

R.