- All Implemented Interfaces:
- Serializable,- Cloneable,- Blob
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.
 
Thread safety
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.
- Since:
- 1.5
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionSerialBlob(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 SummaryModifier and TypeMethodDescriptionclone()Returns a clone of thisSerialBlob.booleanCompares this SerialBlob to the specified object.voidfree()This method frees theSerialBlobobject and releases the resources that it holds.Returns thisSerialBlobobject as an input stream.getBinaryStream(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.longReturns the position in thisSerialBlobobject where the givenBlobobject begins, starting the search at the specified position.setBinaryStream(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 Details- 
SerialBlobConstructs 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
 
- 
SerialBlobConstructs 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:
 
 
- 
- 
Method Details- 
getBytesCopies 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:
 
- 
lengthRetrieves 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
 
- 
getBinaryStreamReturns 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:
 
- 
positionReturns 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
 
- 
positionReturns 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
 
- 
setBytesWrites 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:
 
- 
setBytespublic int setBytes(long pos, byte[] bytes, int offset, int length) throws SerialException, SQLException Writes 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:
 
- 
setBinaryStreamRetrieves 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:
 
- 
truncateTruncates 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
 
- 
getBinaryStreamReturns 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
 
- 
freeThis 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
 
- 
equalsCompares 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.
- 
hashCodepublic int hashCode()Returns a hash code for thisSerialBlob.
- 
cloneReturns 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.
 
-