Serializable, Cloneable, Blob
public class SerialBlob extends Object implements Blob, Serializable, Cloneable
BLOB value.  The SerialBlob class provides a constructor for creating an instance from a Blob object. Note that the Blob object should have brought the SQL BLOB value's data over to the client before a SerialBlob object is constructed from it. The data of an SQL BLOB value can be materialized on the client as an array of bytes (using the method Blob.getBytes) or as a stream of uninterpreted bytes (using the method Blob.getBinaryStream). 
 SerialBlob methods make it possible to make a copy of a SerialBlob object as an array of bytes or as a stream. They also make it possible to locate a given pattern of bytes or a Blob object within a SerialBlob object and to update or truncate a Blob object. 
A SerialBlob is not safe for use by multiple concurrent threads. If a SerialBlob is to be used by more than one thread then access to the SerialBlob should be controlled by appropriate synchronization.
| Constructor | Description | 
|---|---|
| SerialBlob | Constructs a  SerialBlobobject that is a serialized version of the givenbytearray. | 
| SerialBlob | Constructs a  SerialBlobobject that is a serialized version of the givenBlobobject. | 
| Modifier and Type | Method | Description | 
|---|---|---|
| Object | clone() | Returns a clone of this  SerialBlob. | 
| boolean | equals | Compares this SerialBlob to the specified object. | 
| void | free() | This method frees the  SerialBlobobject and releases the resources that it holds. | 
| InputStream | getBinaryStream() | Returns this  SerialBlobobject as an input stream. | 
| InputStream | getBinaryStream | Returns an  InputStreamobject that contains a partialBlobvalue, starting with the byte specified by pos, which is length bytes in length. | 
| byte[] | getBytes | Copies the specified number of bytes, starting at the given position, from this  SerialBlobobject to another array of bytes. | 
| int | hashCode() | Returns a hash code for this  SerialBlob. | 
| long | length() | Retrieves the number of bytes in this  SerialBlobobject's array of bytes. | 
| long | position | Returns the position in this  SerialBlobobject where the given pattern of bytes begins, starting the search at the specified position. | 
| long | position | Returns the position in this  SerialBlobobject where the givenBlobobject begins, starting the search at the specified position. | 
| OutputStream | setBinaryStream | Retrieves a stream that can be used to write to the  BLOBvalue that thisBlobobject represents. | 
| int | setBytes | Writes the given array of bytes to the  BLOBvalue that thisBlobobject represents, starting at positionpos, and returns the number of bytes written. | 
| int | setBytes | Writes all or part of the given  bytearray to theBLOBvalue that thisBlobobject represents and returns the number of bytes written. | 
| void | truncate | Truncates the  BLOBvalue that thisBlobobject represents to belenbytes in length. | 
public SerialBlob(byte[] b) throws SerialException, SQLException
SerialBlob object that is a serialized version of the given byte array.  The new SerialBlob object is initialized with the data from the byte array, thus allowing disconnected RowSet objects to establish serialized Blob objects without touching the data source.
b - the byte array containing the data for the Blob object to be serializedSerialException - if an error occurs during serializationSQLException - if a SQL errors occurspublic SerialBlob(Blob blob) throws SerialException, SQLException
SerialBlob object that is a serialized version of the given Blob object.  The new SerialBlob object is initialized with the data from the Blob object; therefore, the Blob object should have previously brought the SQL BLOB value's data over to the client from the database. Otherwise, the new SerialBlob object will contain no data.
blob - the Blob object from which this SerialBlob object is to be constructed; cannot be null.SerialException - if an error occurs during serializationSQLException - if the Blob passed to this to this constructor is a null.public byte[] getBytes(long pos, int length) throws SerialException
SerialBlob object to another array of bytes.  Note that if the given number of bytes to be copied is larger than the length of this SerialBlob object's array of bytes, the given number will be shortened to the array's length.
getBytes in interface Blob
pos - the ordinal position of the first byte in this SerialBlob object to be copied; numbering starts at 1; must not be less than 1 and must be less than or equal to the length of this SerialBlob objectlength - the number of bytes to be copiedSerialBlob object, starting at the given position and containing the given number of consecutive bytesSerialException - if the given starting position is out of bounds; if free had previously been called on this objectpublic long length() throws SerialException
SerialBlob object's array of bytes.length in interface Blob
long indicating the length in bytes of this SerialBlob object's array of bytesSerialException - if an error occurs; if free had previously been called on this objectpublic InputStream getBinaryStream() throws SerialException
SerialBlob object as an input stream. Unlike the related method, setBinaryStream, a stream is produced regardless of whether the SerialBlob was created with a Blob object or a byte array.getBinaryStream in interface Blob
java.io.InputStream object that contains this SerialBlob object's array of bytesSerialException - if an error occurs; if free had previously been called on this objectpublic long position(byte[] pattern, long start) throws SerialException, SQLException
SerialBlob object where the given pattern of bytes begins, starting the search at the specified position.position in interface Blob
pattern - the pattern of bytes for which to searchstart - the position of the byte in this SerialBlob object from which to begin the search; the first position is 1; must not be less than 1 nor greater than the length of this SerialBlob objectSerialBlob object where the given pattern begins, starting at the specified position; -1 if the pattern is not found or the given starting position is out of bounds; position numbering for the return value starts at 1
SerialException - if an error occurs when serializing the blob; if free had previously been called on this objectSQLException - if there is an error accessing the BLOB value from the databasepublic long position(Blob pattern, long start) throws SerialException, SQLException
SerialBlob object where the given Blob object begins, starting the search at the specified position.position in interface Blob
pattern - the Blob object for which to search;start - the position of the byte in this SerialBlob object from which to begin the search; the first position is 1; must not be less than 1 nor greater than the length of this SerialBlob objectSerialBlob object where the given Blob object begins, starting at the specified position; -1 if the pattern is not found or the given starting position is out of bounds; position numbering for the return value starts at 1
SerialException - if an error occurs when serializing the blob; if free had previously been called on this objectSQLException - if there is an error accessing the BLOB value from the databasepublic int setBytes(long pos, byte[] bytes) throws SerialException, SQLException
BLOB value that this Blob object represents, starting at position pos, and returns the number of bytes written.setBytes in interface Blob
pos - the position in the SQL BLOB value at which to start writing. The first position is 1; must not be less than 1 nor greater than the length+1 of this SerialBlob object.bytes - the array of bytes to be written to the BLOB value that this Blob object representsSerialException - if there is an error accessing the BLOB value; or if an invalid position is set; if free had previously been called on this objectSQLException - if there is an error accessing the BLOB value from the databasepublic int setBytes(long pos, byte[] bytes, int offset, int length) throws SerialException, SQLException
byte array to the BLOB value that this Blob object represents and returns the number of bytes written. Writing starts at position pos in the BLOB value; length bytes from the given byte array are written.setBytes in interface Blob
pos - the position in the BLOB object at which to start writing. The first position is 1; must not be less than 1 nor greater than the length+1 of this SerialBlob object.bytes - the array of bytes to be written to the BLOB valueoffset - the offset into the array bytes at which to start reading the bytes to be set. The first offset position is 0; must not be less than 0 nor greater than the length of the array byteslength - the number of bytes to be written to the BLOB value from the array of bytes bytesSerialException - if there is an error accessing the BLOB value; if an invalid position is set; if an invalid offset value is set; or the combined values of the length and offset is greater than the length of bytes; if free had previously been called on this objectSQLException - if there is an error accessing the BLOB value from the database.public OutputStream setBinaryStream(long pos) throws SerialException, SQLException
BLOB value that this Blob object represents. The stream begins at position pos. This method forwards the setBinaryStream() call to the underlying Blob in the event that this SerialBlob object is instantiated with a Blob. If this SerialBlob is instantiated with a byte array, a SerialException is thrown.setBinaryStream in interface Blob
pos - the position in the BLOB value at which to start writingjava.io.OutputStream object to which data can be writtenSQLException - if there is an error accessing the BLOB valueSerialException - if the SerialBlob in not instantiated with a Blob object that supports setBinaryStream(); if free had previously been called on this objectpublic void truncate(long length) throws SerialException
BLOB value that this Blob object represents to be len bytes in length.truncate in interface Blob
length - the length, in bytes, to which the BLOB value that this Blob object represents should be truncatedSerialException - if there is an error accessing the Blob value; or the length to truncate is greater that the SerialBlob length; if free had previously been called on this objectpublic InputStream getBinaryStream(long pos, long length) throws SQLException
InputStream object that contains a partial Blob value, starting with the byte specified by pos, which is length bytes in length.getBinaryStream in interface Blob
pos - the offset to the first byte of the partial value to be retrieved. The first byte in the Blob is at position 1length - the length in bytes of the partial value to be retrievedInputStream through which the partial Blob value can be read.SQLException - if pos is less than 1 or if pos is greater than the number of bytes in the Blob or if pos + length is greater than the number of bytes in the Blob
SerialException - if the free method had been previously called on this objectpublic void free() throws SQLException
SerialBlob object and releases the resources that it holds. The object is invalid once the free method is called.  If free is called multiple times, the subsequent calls to free are treated as a no-op. 
free in interface Blob
SQLException - if an error occurs releasing the Blob's resourcespublic boolean equals(Object obj)
 true if and only if the argument is not null and is a 
 SerialBlob object that represents the same sequence of bytes as this object.public int hashCode()
SerialBlob.public Object clone()
SerialBlob. The copy will contain a reference to a clone of the internal byte array, not a reference to the original internal byte array of this SerialBlob object. The underlying Blob object will be set to null.
    © 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
    https://docs.oracle.com/en/java/javase/21/docs/api/java.sql.rowset/javax/sql/rowset/serial/SerialBlob.html