protected void populateStreamBlob(int testId,byte[] baseContent,int requiredSize) throws SQLException {
  final byte[] testBytes=generateBlobContent(baseContent,requiredSize);
  try (FbDatabase db=createDatabaseConnection()){
    listener=new SimpleStatementListener();
    transaction=getTransaction(db);
    try {
      statement=db.createStatement(transaction);
      statement.addStatementListener(listener);
      final BlobParameterBuffer blobParameterBuffer=db.createBlobParameterBuffer();
      blobParameterBuffer.addArgument(BlobParameterBuffer.TYPE,BlobParameterBuffer.TYPE_STREAM);
      final FbBlob blob=db.createBlobForOutput(transaction,blobParameterBuffer);
      blob.open();
      int bytesWritten=0;
      while (bytesWritten < testBytes.length) {
        byte[] buffer=new byte[Math.min(blob.getMaximumSegmentSize(),testBytes.length - bytesWritten)];
        System.arraycopy(testBytes,bytesWritten,buffer,0,buffer.length);
        blob.putSegment(buffer);
        bytesWritten+=buffer.length;
      }
      blob.close();
      statement.prepare(INSERT_BLOB_TABLE);
      final DatatypeCoder datatypeCoder=db.getDatatypeCoder();
      FieldValue param1=new FieldValue(datatypeCoder.encodeInt(testId));
      FieldValue param2=new FieldValue(datatypeCoder.encodeLong(blob.getBlobId()));
      statement.execute(RowValue.of(param1,param2));
      statement.close();
    }
  finally {
      transaction.commit();
    }
  }
 }

protected void populateStreamBlob ( int testId , byte [ ] baseContent , int requiredSize ) throws SQLException { final byte [ ] testBytes = generateBlobContent ( baseContent , requiredSize ) ; try ( FbDatabase db = createDatabaseConnection ( ) ) { listener = new SimpleStatementListener ( ) ; transaction = getTransaction ( db ) ; try { statement = db . createStatement ( transaction ) ; statement . addStatementListener ( listener ) ; final BlobParameterBuffer blobParameterBuffer = db . createBlobParameterBuffer ( ) ; blobParameterBuffer . addArgument ( BlobParameterBuffer . TYPE , BlobParameterBuffer . TYPE_STREAM ) ; final FbBlob blob = db . createBlobForOutput ( transaction , blobParameterBuffer ) ; blob . open ( ) ; int bytesWritten = 0 ; while ( bytesWritten < testBytes . length ) { byte [ ] buffer = new byte [ Math . min ( blob . getMaximumSegmentSize ( ) , testBytes . length - bytesWritten ) ] ; System . arraycopy ( testBytes , bytesWritten , buffer , 0 , buffer . length ) ; blob . putSegment ( buffer ) ; bytesWritten += buffer . length ; } blob . close ( ) ; statement . prepare ( INSERT_BLOB_TABLE ) ; final DatatypeCoder datatypeCoder = db . getDatatypeCoder ( ) ; FieldValue param1 = new FieldValue ( datatypeCoder . encodeInt ( testId ) ) ; FieldValue param2 = new FieldValue ( datatypeCoder . encodeLong ( blob . getBlobId ( ) ) ) ; statement . execute ( RowValue . of ( param1 , param2 ) ) ; statement . close ( ) ; } finally { transaction . commit ( ) ; } } }
populates a stream blob for testing .
