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;
}
}
}
Aggregations