- java.lang.Object
- 
- javax.sql.rowset.serial.SerialBlob
 
- 
- All Implemented Interfaces:
- Serializable,- Cloneable,- Blob
 
 public class SerialBlob extends Object implements Blob, Serializable, Cloneable A serialized mapping in the Java programming language of an SQLBLOBvalue.The SerialBlobclass provides a constructor for creating an instance from aBlobobject. Note that theBlobobject should have brought the SQLBLOBvalue's data over to the client before aSerialBlobobject is constructed from it. The data of an SQLBLOBvalue can be materialized on the client as an array of bytes (using the methodBlob.getBytes) or as a stream of uninterpreted bytes (using the methodBlob.getBinaryStream).SerialBlobmethods make it possible to make a copy of aSerialBlobobject as an array of bytes or as a stream. They also make it possible to locate a given pattern of bytes or aBlobobject within aSerialBlobobject and to update or truncate aBlobobject.Thread safetyA 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. - Since:
- 1.5
- See Also:
- Serialized Form
 
- 
- 
Constructor SummaryConstructors Constructor Description SerialBlob(byte[] b)Constructs aSerialBlobobject that is a serialized version of the givenbytearray.SerialBlob(Blob blob)Constructs aSerialBlobobject that is a serialized version of the givenBlobobject.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectclone()Returns a clone of thisSerialBlob.booleanequals(Object obj)Compares this SerialBlob to the specified object.voidfree()This method frees theSerialBlobobject and releases the resources that it holds.InputStreamgetBinaryStream()Returns thisSerialBlobobject as an input stream.InputStreamgetBinaryStream(long pos, long length)Returns anInputStreamobject that contains a partialBlobvalue, starting with the byte specified by pos, which is length bytes in length.byte[]getBytes(long pos, int length)Copies the specified number of bytes, starting at the given position, from thisSerialBlobobject to another array of bytes.inthashCode()Returns a hash code for thisSerialBlob.longlength()Retrieves the number of bytes in thisSerialBlobobject's array of bytes.longposition(byte[] pattern, long start)Returns the position in thisSerialBlobobject where the given pattern of bytes begins, starting the search at the specified position.longposition(Blob pattern, long start)Returns the position in thisSerialBlobobject where the givenBlobobject begins, starting the search at the specified position.OutputStreamsetBinaryStream(long pos)Retrieves a stream that can be used to write to theBLOBvalue that thisBlobobject represents.intsetBytes(long pos, byte[] bytes)Writes the given array of bytes to theBLOBvalue that thisBlobobject represents, starting at positionpos, and returns the number of bytes written.intsetBytes(long pos, byte[] bytes, int offset, int length)Writes all or part of the givenbytearray to theBLOBvalue that thisBlobobject represents and returns the number of bytes written.voidtruncate(long length)Truncates theBLOBvalue that thisBlobobject represents to belenbytes in length.
 
- 
- 
- 
Constructor Detail- 
SerialBlobpublic SerialBlob(byte[] b) throws SerialException, SQLExceptionConstructs aSerialBlobobject that is a serialized version of the givenbytearray.The new SerialBlobobject is initialized with the data from thebytearray, thus allowing disconnectedRowSetobjects to establish serializedBlobobjects without touching the data source.- Parameters:
- b- the- bytearray containing the data for the- Blobobject to be serialized
- Throws:
- SerialException- if an error occurs during serialization
- SQLException- if a SQL errors occurs
 
 - 
SerialBlobpublic SerialBlob(Blob blob) throws SerialException, SQLException Constructs aSerialBlobobject that is a serialized version of the givenBlobobject.The new SerialBlobobject is initialized with the data from theBlobobject; therefore, theBlobobject should have previously brought the SQLBLOBvalue's data over to the client from the database. Otherwise, the newSerialBlobobject will contain no data.- Parameters:
- blob- the- Blobobject from which this- SerialBlobobject is to be constructed; cannot be null.
- Throws:
- SerialException- if an error occurs during serialization
- SQLException- if the- Blobpassed to this to this constructor is a- null.
- See Also:
- Blob
 
 
- 
 - 
Method Detail- 
getBytespublic byte[] getBytes(long pos, int length) throws SerialExceptionCopies the specified number of bytes, starting at the given position, from thisSerialBlobobject to another array of bytes.Note that if the given number of bytes to be copied is larger than the length of this SerialBlobobject's array of bytes, the given number will be shortened to the array's length.- Specified by:
- getBytesin interface- Blob
- Parameters:
- pos- the ordinal position of the first byte in this- SerialBlobobject to be copied; numbering starts at- 1; must not be less than- 1and must be less than or equal to the length of this- SerialBlobobject
- length- the number of bytes to be copied
- Returns:
- an array of bytes that is a copy of a region of this
         SerialBlobobject, starting at the given position and containing the given number of consecutive bytes
- Throws:
- SerialException- if the given starting position is out of bounds; if- freehad previously been called on this object
- See Also:
- Blob.setBytes(long, byte[])
 
 - 
lengthpublic long length() throws SerialExceptionRetrieves the number of bytes in thisSerialBlobobject's array of bytes.- Specified by:
- lengthin interface- Blob
- Returns:
- a longindicating the length in bytes of thisSerialBlobobject's array of bytes
- Throws:
- SerialException- if an error occurs; if- freehad previously been called on this object
 
 - 
getBinaryStreampublic InputStream getBinaryStream() throws SerialException Returns thisSerialBlobobject as an input stream. Unlike the related method,setBinaryStream, a stream is produced regardless of whether theSerialBlobwas created with aBlobobject or abytearray.- Specified by:
- getBinaryStreamin interface- Blob
- Returns:
- a java.io.InputStreamobject that contains thisSerialBlobobject's array of bytes
- Throws:
- SerialException- if an error occurs; if- freehad previously been called on this object
- See Also:
- setBinaryStream(long)
 
 - 
positionpublic long position(byte[] pattern, long start) throws SerialException, SQLExceptionReturns the position in thisSerialBlobobject where the given pattern of bytes begins, starting the search at the specified position.- Specified by:
- positionin interface- Blob
- Parameters:
- pattern- the pattern of bytes for which to search
- start- the position of the byte in this- SerialBlobobject from which to begin the search; the first position is- 1; must not be less than- 1nor greater than the length of this- SerialBlobobject
- Returns:
- the position in this SerialBlobobject where the given pattern begins, starting at the specified position;-1if the pattern is not found or the given starting position is out of bounds; position numbering for the return value starts at1
- Throws:
- SerialException- if an error occurs when serializing the blob; if- freehad previously been called on this object
- SQLException- if there is an error accessing the- BLOBvalue from the database
 
 - 
positionpublic long position(Blob pattern, long start) throws SerialException, SQLException Returns the position in thisSerialBlobobject where the givenBlobobject begins, starting the search at the specified position.- Specified by:
- positionin interface- Blob
- Parameters:
- pattern- the- Blobobject for which to search;
- start- the position of the byte in this- SerialBlobobject from which to begin the search; the first position is- 1; must not be less than- 1nor greater than the length of this- SerialBlobobject
- Returns:
- the position in this SerialBlobobject where the givenBlobobject begins, starting at the specified position;-1if the pattern is not found or the given starting position is out of bounds; position numbering for the return value starts at1
- Throws:
- SerialException- if an error occurs when serializing the blob; if- freehad previously been called on this object
- SQLException- if there is an error accessing the- BLOBvalue from the database
 
 - 
setBytespublic int setBytes(long pos, byte[] bytes) throws SerialException, SQLExceptionWrites the given array of bytes to theBLOBvalue that thisBlobobject represents, starting at positionpos, and returns the number of bytes written.- Specified by:
- setBytesin interface- Blob
- Parameters:
- pos- the position in the SQL- BLOBvalue at which to start writing. The first position is- 1; must not be less than- 1nor greater than the length of this- SerialBlobobject.
- bytes- the array of bytes to be written to the- BLOBvalue that this- Blobobject represents
- Returns:
- the number of bytes written
- Throws:
- SerialException- if there is an error accessing the- BLOBvalue; or if an invalid position is set; if an invalid offset value is set; if- freehad previously been called on this object
- SQLException- if there is an error accessing the- BLOBvalue from the database
- See Also:
- getBytes(long, int)
 
 - 
setBytespublic int setBytes(long pos, byte[] bytes, int offset, int length) throws SerialException, SQLExceptionWrites all or part of the givenbytearray to theBLOBvalue that thisBlobobject represents and returns the number of bytes written. Writing starts at positionposin theBLOBvalue; len bytes from the given byte array are written.- Specified by:
- setBytesin interface- Blob
- Parameters:
- pos- the position in the- BLOBobject at which to start writing. The first position is- 1; must not be less than- 1nor greater than the length of this- SerialBlobobject.
- bytes- the array of bytes to be written to the- BLOBvalue
- offset- the offset in the- bytearray at which to start reading the bytes. The first offset position is- 0; must not be less than- 0nor greater than the length of the- bytearray
- length- the number of bytes to be written to the- BLOBvalue from the array of bytes bytes.
- Returns:
- the number of bytes written
- Throws:
- SerialException- if there is an error accessing the- BLOBvalue; if an invalid position is set; if an invalid offset value is set; if number of bytes to be written is greater than the- SerialBloblength; or the combined values of the length and offset is greater than the Blob buffer; if- freehad previously been called on this object
- SQLException- if there is an error accessing the- BLOBvalue from the database.
- See Also:
- getBytes(long, int)
 
 - 
setBinaryStreampublic OutputStream setBinaryStream(long pos) throws SerialException, SQLException Retrieves a stream that can be used to write to theBLOBvalue that thisBlobobject represents. The stream begins at positionpos. This method forwards thesetBinaryStream()call to the underlyingBlobin the event that thisSerialBlobobject is instantiated with aBlob. If thisSerialBlobis instantiated with abytearray, aSerialExceptionis thrown.- Specified by:
- setBinaryStreamin interface- Blob
- Parameters:
- pos- the position in the- BLOBvalue at which to start writing
- Returns:
- a java.io.OutputStreamobject to which data can be written
- Throws:
- SQLException- if there is an error accessing the- BLOBvalue
- SerialException- if the SerialBlob in not instantiated with a- Blobobject that supports- setBinaryStream(); if- freehad previously been called on this object
- See Also:
- getBinaryStream()
 
 - 
truncatepublic void truncate(long length) throws SerialExceptionTruncates theBLOBvalue that thisBlobobject represents to belenbytes in length.- Specified by:
- truncatein interface- Blob
- Parameters:
- length- the length, in bytes, to which the- BLOBvalue that this- Blobobject represents should be truncated
- Throws:
- SerialException- if there is an error accessing the Blob value; or the length to truncate is greater that the SerialBlob length; if- freehad previously been called on this object
 
 - 
getBinaryStreampublic InputStream getBinaryStream(long pos, long length) throws SQLException Returns anInputStreamobject that contains a partialBlobvalue, starting with the byte specified by pos, which is length bytes in length.- Specified by:
- getBinaryStreamin interface- Blob
- Parameters:
- pos- the offset to the first byte of the partial value to be retrieved. The first byte in the- Blobis at position 1
- length- the length in bytes of the partial value to be retrieved
- Returns:
- InputStreamthrough which the partial- Blobvalue can be read.
- Throws:
- SQLException- if pos is less than 1 or if pos is greater than the number of bytes in the- Blobor if pos + length is greater than the number of bytes in the- Blob
- SerialException- if the- freemethod had been previously called on this object
- Since:
- 1.6
 
 - 
freepublic void free() throws SQLExceptionThis method frees theSerialBlobobject and releases the resources that it holds. The object is invalid once thefreemethod is called.If freeis called multiple times, the subsequent calls tofreeare treated as a no-op.- Specified by:
- freein interface- Blob
- Throws:
- SQLException- if an error occurs releasing the Blob's resources
- Since:
- 1.6
 
 - 
equalspublic boolean equals(Object obj) Compares this SerialBlob to the specified object. The result istrueif and only if the argument is notnulland is aSerialBlobobject that represents the same sequence of bytes as this object.- Overrides:
- equalsin class- Object
- Parameters:
- obj- The object to compare this- SerialBlobagainst
- Returns:
- trueif the given object represents a- SerialBlobequivalent to this SerialBlob,- falseotherwise
- See Also:
- Object.hashCode(),- HashMap
 
 - 
hashCodepublic int hashCode() Returns a hash code for thisSerialBlob.- Overrides:
- hashCodein class- Object
- Returns:
- a hash code value for this object.
- See Also:
- Object.equals(java.lang.Object),- System.identityHashCode(java.lang.Object)
 
 - 
clonepublic Object clone() Returns a clone of thisSerialBlob. The copy will contain a reference to a clone of the internal byte array, not a reference to the original internal byte array of thisSerialBlobobject. The underlyingBlobobject will be set to null.
 
- 
 
-