org.postgresql.jdbc.PgBlob Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mogdb-jdbc Show documentation
Show all versions of mogdb-jdbc Show documentation
Java JDBC driver for MogDB
/*
* Copyright (c) 2004, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package io.mogdb.jdbc;
import io.mogdb.largeobject.LargeObject;
import java.sql.SQLException;
public class PgBlob extends AbstractBlobClob implements java.sql.Blob {
public PgBlob(io.mogdb.core.BaseConnection conn, long oid) throws SQLException {
super(conn, oid);
}
public synchronized java.io.InputStream getBinaryStream(long pos, long length)
throws SQLException {
checkFreed();
LargeObject subLO = getLo(false).copy();
addSubLO(subLO);
if (pos > Integer.MAX_VALUE) {
subLO.seek64(pos - 1, LargeObject.SEEK_SET);
} else {
subLO.seek((int) pos - 1, LargeObject.SEEK_SET);
}
return subLO.getInputStream(length);
}
public synchronized int setBytes(long pos, byte[] bytes) throws SQLException {
return setBytes(pos, bytes, 0, bytes.length);
}
public synchronized int setBytes(long pos, byte[] bytes, int offset, int len)
throws SQLException {
assertPosition(pos);
getLo(true).seek((int) (pos - 1));
getLo(true).write(bytes, offset, len);
return len;
}
}