public class LargeObject extends Object implements AutoCloseable
This class provides the basic methods required to run the interface, plus a pair of methods that provide InputStream and OutputStream classes for this object.
Normally, client code would use the getAsciiStream, getBinaryStream, or getUnicodeStream methods in ResultSet, or setAsciiStream, setBinaryStream, or setUnicodeStream methods in PreparedStatement to access Large Objects.
However, sometimes lower level access to Large Objects are required, that are not supported by the JDBC specification.
Refer to org.postgresql.largeobject.LargeObjectManager on how to gain access to a Large Object, or how to create one.
LargeObjectManager
,
ResultSet.getAsciiStream(int)
,
ResultSet.getBinaryStream(int)
,
ResultSet.getUnicodeStream(int)
,
PreparedStatement.setAsciiStream(int, java.io.InputStream, int)
,
PreparedStatement.setBinaryStream(int, java.io.InputStream, int)
,
PreparedStatement.setUnicodeStream(int, java.io.InputStream, int)
Modifier and Type | Field and Description |
---|---|
static int |
SEEK_CUR
Indicates a seek from the current position.
|
static int |
SEEK_END
Indicates a seek from the end of a file.
|
static int |
SEEK_SET
Indicates a seek from the beginning of a file.
|
Modifier | Constructor and Description |
---|---|
protected |
LargeObject(Fastpath fp,
long oid,
int mode)
This opens a large object.
|
protected |
LargeObject(Fastpath fp,
long oid,
int mode,
@Nullable BaseConnection conn,
boolean commitOnClose)
This opens a large object.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
This method closes the object.
|
LargeObject |
copy() |
InputStream |
getInputStream()
Returns an
InputStream from this object. |
InputStream |
getInputStream(long limit)
Returns an
InputStream from this object, that will limit the amount of data that is
visible. |
long |
getLongOID() |
int |
getOID()
Deprecated.
As of 8.3, replaced by
getLongOID() |
OutputStream |
getOutputStream()
Returns an
OutputStream to this object. |
int |
read(byte[] buf,
int off,
int len)
Reads some data from the object into an existing array.
|
byte[] |
read(int len)
Reads some data from the object, and return as a byte[] array.
|
void |
seek(int pos)
Sets the current position within the object.
|
void |
seek(int pos,
int ref)
Sets the current position within the object.
|
void |
seek64(long pos,
int ref)
Sets the current position within the object using 64-bit value (9.3+).
|
int |
size()
This method is inefficient, as the only way to find out the size of the object is to seek to
the end, record the current position, then return to the original position.
|
long |
size64()
See #size() for information about efficiency.
|
int |
tell() |
long |
tell64() |
void |
truncate(int len)
Truncates the large object to the given length in bytes.
|
void |
truncate64(long len)
Truncates the large object to the given length in bytes.
|
void |
write(byte[] buf)
Writes an array to the object.
|
void |
write(byte[] buf,
int off,
int len)
Writes some data from an array to the object.
|
public static final int SEEK_SET
public static final int SEEK_CUR
public static final int SEEK_END
protected LargeObject(Fastpath fp, long oid, int mode, @Nullable BaseConnection conn, boolean commitOnClose) throws SQLException
This opens a large object.
If the object does not exist, then an SQLException is thrown.
fp
- FastPath API for the connection to useoid
- of the Large Object to openmode
- Mode of opening the large objectconn
- the connection to the database used to access this LOBcommitOnClose
- commit the transaction when this LOB will be closed (defined in
LargeObjectManager)SQLException
- if a database-access error occurs.LargeObjectManager
protected LargeObject(Fastpath fp, long oid, int mode) throws SQLException
This opens a large object.
If the object does not exist, then an SQLException is thrown.
fp
- FastPath API for the connection to useoid
- of the Large Object to openmode
- Mode of opening the large object (defined in LargeObjectManager)SQLException
- if a database-access error occurs.LargeObjectManager
public LargeObject copy() throws SQLException
SQLException
@Deprecated public int getOID()
getLongOID()
public long getLongOID()
public void close() throws SQLException
close
in interface AutoCloseable
SQLException
- if a database-access error occurs.public byte[] read(int len) throws SQLException
len
- number of bytes to readSQLException
- if a database-access error occurs.public int read(byte[] buf, int off, int len) throws SQLException
buf
- destination arrayoff
- offset within arraylen
- number of bytes to readSQLException
- if a database-access error occurs.public void write(byte[] buf) throws SQLException
buf
- array to writeSQLException
- if a database-access error occurs.public void write(byte[] buf, int off, int len) throws SQLException
buf
- destination arrayoff
- offset within arraylen
- number of bytes to writeSQLException
- if a database-access error occurs.public void seek(int pos, int ref) throws SQLException
Sets the current position within the object.
This is similar to the fseek() call in the standard C library. It allows you to have random access to the large object.
pos
- position within objectref
- Either SEEK_SET, SEEK_CUR or SEEK_ENDSQLException
- if a database-access error occurs.public void seek64(long pos, int ref) throws SQLException
pos
- position within objectref
- Either SEEK_SET, SEEK_CUR or SEEK_ENDSQLException
- if a database-access error occurs.public void seek(int pos) throws SQLException
Sets the current position within the object.
This is similar to the fseek() call in the standard C library. It allows you to have random access to the large object.
pos
- position within object from beginningSQLException
- if a database-access error occurs.public int tell() throws SQLException
SQLException
- if a database-access error occurs.public long tell64() throws SQLException
SQLException
- if a database-access error occurs.public int size() throws SQLException
This method is inefficient, as the only way to find out the size of the object is to seek to the end, record the current position, then return to the original position.
A better method will be found in the future.
SQLException
- if a database-access error occurs.public long size64() throws SQLException
SQLException
- if a database-access error occurs.public void truncate(int len) throws SQLException
len
- given length in bytesSQLException
- if something goes wrongpublic void truncate64(long len) throws SQLException
len
- given length in bytesSQLException
- if something goes wrongpublic InputStream getInputStream() throws SQLException
Returns an InputStream
from this object.
This InputStream
can then be used in any method that requires an InputStream.
InputStream
from this objectSQLException
- if a database-access error occurs.public InputStream getInputStream(long limit) throws SQLException
InputStream
from this object, that will limit the amount of data that is
visible.limit
- maximum number of bytes the resulting stream will serveInputStream
from this objectSQLException
- if a database-access error occurs.public OutputStream getOutputStream() throws SQLException
Returns an OutputStream
to this object.
This OutputStream can then be used in any method that requires an OutputStream.
OutputStream
from this objectSQLException
- if a database-access error occurs.Copyright © 1997-2020 PostgreSQL Global Development Group. All Rights Reserved.