use of org.firebirdsql.gds.ng.FbBlob in project jaybird by FirebirdSQL.
the class TestV10OutputBlob method testDoubleOpen.
/**
* Test double open is not allowed.
*/
@Test
public void testDoubleOpen() throws Exception {
expectedException.expect(SQLNonTransientException.class);
expectedException.expect(allOf(errorCodeEquals(ISCConstants.isc_no_segstr_close), fbMessageStartsWith(ISCConstants.isc_no_segstr_close)));
try (FbWireDatabase db = createDatabaseConnection()) {
final FbTransaction transaction = getTransaction(db);
try {
final FbBlob blob = db.createBlobForOutput(transaction, null);
blob.open();
blob.open();
} finally {
transaction.commit();
}
}
}
use of org.firebirdsql.gds.ng.FbBlob 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