Package java.sql
Interface Blob
-
public interface BlobA Java interface representing the SQLBLOBtype.An SQL
BLOBtype stores a large array of binary data (bytes) as the value in a column of a database.The
java.sql.Blobinterface provides methods for setting and retrieving data in theBlob, for queryingBlobdata length, and for searching for data within theBlob.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidfree()Frees any resources held by this blob.InputStreamgetBinaryStream()Retrieves thisBlobobject as a binary stream.InputStreamgetBinaryStream(long pos, long length)Retrieveslengthbytes from thisBlob, starting at 1-based offsetpos, and returns them as a binary stream.byte[]getBytes(long pos, int length)Gets a portion of the value of thisBlobas an array of bytes.longlength()Gets the number of bytes in thisBlobobject.longposition(byte[] pattern, long start)Search for the position in thisBlobat which the specified pattern begins, starting at a specified position within theBlob.longposition(Blob pattern, long start)Search for the position in thisBlobat which a specified pattern begins, starting at a specified position within theBlob.OutputStreamsetBinaryStream(long pos)Gets a stream that can be used to write binary data to thisBlob.intsetBytes(long pos, byte[] theBytes)Writes a specified array of bytes to thisBlobobject, starting at a specified position.intsetBytes(long pos, byte[] theBytes, int offset, int len)Writes a portion of a specified byte array to thisBlob.voidtruncate(long len)Truncate the value of thisBlobobject to a specified length in bytes.
-
-
-
Method Detail
-
getBinaryStream
InputStream getBinaryStream() throws SQLException
Retrieves thisBlobobject as a binary stream.- Returns:
- a binary
InputStreamgiving access to theBlobdata. - Throws:
SQLException- if an error occurs accessing theBlob.
-
getBinaryStream
InputStream getBinaryStream(long pos, long length) throws SQLException
Retrieveslengthbytes from thisBlob, starting at 1-based offsetpos, and returns them as a binary stream.- Returns:
- a binary
InputStreamgiving access to theBlobdata. - Throws:
SQLException- if an error occurs accessing theBlob.
-
getBytes
byte[] getBytes(long pos, int length) throws SQLExceptionGets a portion of the value of thisBlobas an array of bytes.- Parameters:
pos- the position of the first byte in theBlobto get, where the first byte in theBlobhas position 1.length- the number of bytes to get.- Returns:
- a byte array containing the data from the
Blob, starting atposand is up tolengthbytes long. - Throws:
SQLException- if an error occurs accessing theBlob.
-
length
long length() throws SQLExceptionGets the number of bytes in thisBlobobject.- Returns:
- a
longvalue with the length of theBlobin bytes. - Throws:
SQLException- if an error occurs accessing theBlob.
-
position
long position(Blob pattern, long start) throws SQLException
Search for the position in thisBlobat which a specified pattern begins, starting at a specified position within theBlob.- Parameters:
pattern- aBlobcontaining the pattern of data to search for in thisBlob.start- the position within thisBlobto start the search, where the first position in theBlobis1.- Returns:
- a
longvalue with the position at which the pattern begins. Returns-1if the pattern is not found in thisBlob. - Throws:
SQLException- if an error occurs accessing theBlob.
-
position
long position(byte[] pattern, long start) throws SQLExceptionSearch for the position in thisBlobat which the specified pattern begins, starting at a specified position within theBlob.- Parameters:
pattern- a byte array containing the pattern of data to search for in thisBlob.start- the position within thisBlobto start the search, where the first position in theBlobis1.- Returns:
- a
longvalue with the position at which the pattern begins. Returns-1if the pattern is not found in thisBlob. - Throws:
SQLException- if an error occurs accessing theBlob.
-
setBinaryStream
OutputStream setBinaryStream(long pos) throws SQLException
Gets a stream that can be used to write binary data to thisBlob.- Parameters:
pos- the position within thisBlobat which to start writing, where the first position in theBlobis1.- Returns:
- a binary
InputStreamwhich can be used to write data into theBlobstarting at the specified position. - Throws:
SQLException- if an error occurs accessing theBlob.
-
setBytes
int setBytes(long pos, byte[] theBytes) throws SQLExceptionWrites a specified array of bytes to thisBlobobject, starting at a specified position. Returns the number of bytes written.- Parameters:
pos- the position within thisBlobat which to start writing, where the first position in theBlobis1.theBytes- an array of bytes to write into theBlob.- Returns:
- an integer containing the number of bytes written to the
Blob. - Throws:
SQLException- if an error occurs accessing theBlob.
-
setBytes
int setBytes(long pos, byte[] theBytes, int offset, int len) throws SQLExceptionWrites a portion of a specified byte array to thisBlob. Returns the number of bytes written.- Parameters:
pos- the position within thisBlobat which to start writing, where the first position in theBlobis1.theBytes- an array of bytes to write into theBlob.offset- the offset into the byte array from which to start writing data - the first byte in the array has offset0.len- the length of data to write in number of bytes.- Returns:
- an integer containing the number of bytes written to the
Blob. - Throws:
SQLException- if an error occurs accessing theBlob.
-
truncate
void truncate(long len) throws SQLExceptionTruncate the value of thisBlobobject to a specified length in bytes.- Parameters:
len- the length of data in bytes after which thisBlobis to be truncated.- Throws:
SQLException- if an error occurs accessing theBlob.
-
free
void free() throws SQLException
Frees any resources held by this blob. Afterfreeis called, calling method other thanfreewill throwSQLException(callingfreerepeatedly will do nothing).- Throws:
SQLException
-
-