Search in sources :

Example 1 with Synchronizable

use of org.firebirdsql.jdbc.Synchronizable in project jaybird by FirebirdSQL.

the class FBBlobField method getBytesInternal.

public byte[] getBytesInternal() throws SQLException {
    final byte[] blobIdBuffer = getFieldData();
    if (blobIdBuffer == null)
        return null;
    final long blobId = getDatatypeCoder().decodeLong(blobIdBuffer);
    synchronized (((Synchronizable) getBlob()).getSynchronizationObject()) {
        try (FbBlob blobHandle = gdsHelper.openBlob(blobId, FBBlob.SEGMENTED)) {
            final int blobLength = (int) blobHandle.length();
            final int bufferLength = gdsHelper.getBlobBufferLength();
            final byte[] resultBuffer = new byte[blobLength];
            int offset = 0;
            while (offset < blobLength) {
                final byte[] segmentBuffer = blobHandle.getSegment(bufferLength);
                if (segmentBuffer.length == 0) {
                    // unexpected EOF
                    throw new TypeConversionException(BYTES_CONVERSION_ERROR);
                }
                System.arraycopy(segmentBuffer, 0, resultBuffer, offset, segmentBuffer.length);
                offset += segmentBuffer.length;
            }
            return resultBuffer;
        }
    }
}
Also used : Synchronizable(org.firebirdsql.jdbc.Synchronizable) FbBlob(org.firebirdsql.gds.ng.FbBlob)

Aggregations

FbBlob (org.firebirdsql.gds.ng.FbBlob)1 Synchronizable (org.firebirdsql.jdbc.Synchronizable)1