本文整理汇总了Java中java.sql.Blob.setBinaryStream方法的典型用法代码示例。如果您正苦于以下问题:Java Blob.setBinaryStream方法的具体用法?Java Blob.setBinaryStream怎么用?Java Blob.setBinaryStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Blob
的用法示例。
在下文中一共展示了Blob.setBinaryStream方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mergeBlob
import java.sql.Blob; //导入方法依赖的package包/类
@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 );
}
}
示例2: setReplicationDataBlob
import java.sql.Blob; //导入方法依赖的package包/类
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 );
}
示例3: doWriteDerby
import java.sql.Blob; //导入方法依赖的package包/类
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);
}
}
示例4: doWriteDerby
import java.sql.Blob; //导入方法依赖的package包/类
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);
}
}
示例5: next
import java.sql.Blob; //导入方法依赖的package包/类
@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);
}
}