- 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.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SerialBlob(Blob blob)Constructs aSerialBlobobject that is a serialized version of the givenBlobobject.SerialBlob(byte[] b)Constructs aSerialBlobobject that is a serialized version of the givenbytearray.
-
Method Summary
Methods Modifier and Type Method and Description voidfree()This method frees theBlobobject 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.longlength()Retrieves the number of bytes in thisSerialBlobobject's array of bytes.longposition(Blob pattern, long start)Returns the position in thisSerialBlobobject where the givenBlobobject begins, starting the search at the specified position.longposition(byte[] pattern, long start)Returns the position in thisSerialBlobobject where the given pattern of bytes 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
-
SerialBlob
public 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- thebytearray containing the data for theBlobobject to be serialized- Throws:
SerialException- if an error occurs during serializationSQLException- if a SQL errors occurs
-
SerialBlob
public 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- theBlobobject from which thisSerialBlobobject is to be constructed; cannot be null.- Throws:
SerialException- if an error occurs during serializationSQLException- if theBlobpassed to this to this constructor is anull.- See Also:
Blob
-
-
Method Detail
-
getBytes
public 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 interfaceBlob- Parameters:
pos- the ordinal position of the first byte in thisSerialBlobobject to be copied; numbering starts at1; must not be less than1and must be less than or equal to the length of thisSerialBlobobjectlength- 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- See Also:
Blob.setBytes(long, byte[])
-
length
public long length() throws SerialExceptionRetrieves the number of bytes in thisSerialBlobobject's array of bytes.- Specified by:
lengthin interfaceBlob- Returns:
- a
longindicating the length in bytes of thisSerialBlobobject's array of bytes - Throws:
SerialException- if an error occurs
-
getBinaryStream
public 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 interfaceBlob- Returns:
- a
java.io.InputStreamobject that contains thisSerialBlobobject's array of bytes - Throws:
SerialException- if an error occurs- See Also:
setBinaryStream(long)
-
position
public 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 interfaceBlob- Parameters:
pattern- the pattern of bytes for which to searchstart- the position of the byte in thisSerialBlobobject from which to begin the search; the first position is1; must not be less than1nor greater than the length of thisSerialBlobobject- 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 blobSQLException- if there is an error accessing theBLOBvalue from the database
-
position
public 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 interfaceBlob- Parameters:
pattern- theBlobobject for which to search;start- the position of the byte in thisSerialBlobobject from which to begin the search; the first position is1; must not be less than1nor greater than the length of thisSerialBlobobject- 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 blobSQLException- if there is an error accessing theBLOBvalue from the database
-
setBytes
public 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 interfaceBlob- Parameters:
pos- the position in the SQLBLOBvalue at which to start writing. The first position is1; must not be less than1nor greater than the length of thisSerialBlobobject.bytes- the array of bytes to be written to theBLOBvalue that thisBlobobject represents- Returns:
- the number of bytes written
- Throws:
SerialException- if there is an error accessing theBLOBvalue; or if an invalid position is set; if an invalid offset value is setSQLException- if there is an error accessing theBLOBvalue from the database- See Also:
getBytes(long, int)
-
setBytes
public 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 interfaceBlob- Parameters:
pos- the position in theBLOBobject at which to start writing. The first position is1; must not be less than1nor greater than the length of thisSerialBlobobject.bytes- the array of bytes to be written to theBLOBvalueoffset- the offset in thebytearray at which to start reading the bytes. The first offset position is0; must not be less than0nor greater than the length of thebytearraylength- the number of bytes to be written to theBLOBvalue from the array of bytes bytes.- Returns:
- the number of bytes written
- Throws:
SerialException- if there is an error accessing theBLOBvalue; if an invalid position is set; if an invalid offset value is set; if number of bytes to be written is greater than theSerialBloblength; or the combined values of the length and offset is greater than the Blob bufferSQLException- if there is an error accessing theBLOBvalue from the database.- See Also:
getBytes(long, int)
-
setBinaryStream
public 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 interfaceBlob- Parameters:
pos- the position in theBLOBvalue at which to start writing- Returns:
- a
java.io.OutputStreamobject to which data can be written - Throws:
SQLException- if there is an error accessing theBLOBvalueSerialException- if the SerialBlob in not instantiated with aBlobobject that supportssetBinaryStream()- See Also:
getBinaryStream()
-
truncate
public void truncate(long length) throws SerialExceptionTruncates theBLOBvalue that thisBlobobject represents to belenbytes in length.- Specified by:
truncatein interfaceBlob- Parameters:
length- the length, in bytes, to which theBLOBvalue that thisBlobobject 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
-
getBinaryStream
public 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 interfaceBlob- Parameters:
pos- the offset to the first byte of the partial value to be retrieved. The first byte in theBlobis at position 1length- the length in bytes of the partial value to be retrieved- Returns:
InputStreamthrough which the partialBlobvalue can be read.- Throws:
SQLException- if pos is less than 1 or if pos is greater than the number of bytes in theBlobor if pos + length is greater than the number of bytes in theBlob- Since:
- 1.6
-
free
public void free() throws SQLExceptionThis method frees theBlobobject and releases the resources that it holds.Blobobject. The object is invalid once thefreemethod is called. Iffreeis called multiple times, the subsequent calls tofreeare treated as a no-op.- Specified by:
freein interfaceBlob- Throws:
SQLException- if an error occurs releasing the Blob's resources- Since:
- 1.6
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
04/10/2025 15:52:48 Cette version de la page est en cache (à la date du 04/10/2025 15:52:48) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 01/09/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/sql/rowset/serial/SerialBlob.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.