Java Code Examples for java.sql.Blob.setBinaryStream()

The following are Jave code examples for showing how to use setBinaryStream() of the java.sql.Blob class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: Dialect.java   View Source Code Vote up 7 votes
@Override
public Blob mergeBlob(Blob original, Blob target, SessionImplementor session) {
	if ( original != target ) {
		try {
			// the BLOB just read during the load phase of merge
			final OutputStream connectedStream = target.setBinaryStream( 1L );
			// the BLOB from the detached state
			final InputStream detachedStream = original.getBinaryStream();
			StreamCopier.copy( detachedStream, connectedStream );
			return target;
		}
		catch (SQLException e ) {
			throw session.getFactory().getSQLExceptionHelper().convert( e, "unable to merge BLOB data" );
		}
	}
	else {
		return NEW_LOCATOR_LOB_MERGE_STRATEGY.mergeBlob( original, target, session );
	}
}
 
Example 2
Project: neoscada   File: AbstractJdbcStorageDao.java   View Source Code Vote up 6 votes
private static void setReplicationDataBlob ( final PreparedStatement stmt, final Event event ) throws SQLException, IOException
{
    final Blob blob = stmt.getConnection ().createBlob ();

    final ObjectOutputStream oos = new ObjectOutputStream ( blob.setBinaryStream ( 1 ) );
    oos.writeObject ( event );
    oos.close ();

    stmt.setBlob ( 4, blob );
}
 
Example 3
Project: syndesis   File: SqlIconFileStore.java   View Source Code Vote up 6 votes
private void doWriteDerby(Handle h, String id, InputStream file) {
    doDelete(h, id);
    try {
        Blob blob = h.getConnection().createBlob();
        try (OutputStream out = blob.setBinaryStream(1)) {
            IOUtils.copy(file, out);
        }

        h.insert("INSERT INTO icon_filestore(id, data) values (?,?)", id, blob);
    } catch (IOException | SQLException ex) {
        throw IconDataAccessException.launderThrowable(ex);
    }
}
 
Example 4
Project: syndesis   File: SqlExtensionFileStore.java   View Source Code Vote up 6 votes
private void doWriteDerby(Handle h, String path, InputStream file) {
    doDelete(h, path);
    try {
        Blob blob = h.getConnection().createBlob();
        try (OutputStream out = blob.setBinaryStream(1)) {
            IOUtils.copy(file, out);
        }

        h.insert("INSERT INTO filestore(path, data) values (?,?)", path, blob);
    } catch (IOException | SQLException ex) {
        throw ExtensionDataAccessException.launderThrowable(ex);
    }
}
 
Example 5
Project: aliyun-maxcompute-data-collectors   File: BlobGenerator.java   View Source Code Vote up 6 votes
@Override
public Blob next() {
  try {
    Blob blob =
        (Blob) methCreateTemporary.invoke(null, conn, false, durationSession);

    int blobSize =
        (int) (rng.nextDouble() * (maxBytes - minBytes) + minBytes);
    byte[] blobData = new byte[blobSize];
    rng.nextBytes(blobData);

    // blob.setBytes(blobData);

    OutputStream os = blob.setBinaryStream(1);
    InputStream is = new ByteArrayInputStream(blobData);
    int bufferSize = (Integer) methGetBufferSize.invoke(blob);
    byte[] buffer = new byte[bufferSize];
    int bytesRead = 0;
    while ((bytesRead = is.read(buffer)) != -1) {
      os.write(buffer, 0, bytesRead);
    }
    os.close();
    is.close();

    return blob;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}