- 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 SQLBLOB
value.The
SerialBlob
class provides a constructor for creating an instance from aBlob
object. Note that theBlob
object should have brought the SQLBLOB
value's data over to the client before aSerialBlob
object is constructed from it. The data of an SQLBLOB
value 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
).SerialBlob
methods make it possible to make a copy of aSerialBlob
object as an array of bytes or as a stream. They also make it possible to locate a given pattern of bytes or aBlob
object within aSerialBlob
object and to update or truncate aBlob
object.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SerialBlob(Blob blob)
Constructs aSerialBlob
object that is a serialized version of the givenBlob
object.SerialBlob(byte[] b)
Constructs aSerialBlob
object that is a serialized version of the givenbyte
array.
-
Method Summary
Methods Modifier and Type Method and Description void
free()
This method frees theBlob
object and releases the resources that it holds.InputStream
getBinaryStream()
Returns thisSerialBlob
object as an input stream.InputStream
getBinaryStream(long pos, long length)
Returns anInputStream
object that contains a partialBlob
value, 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 thisSerialBlob
object to another array of bytes.long
length()
Retrieves the number of bytes in thisSerialBlob
object's array of bytes.long
position(Blob pattern, long start)
Returns the position in thisSerialBlob
object where the givenBlob
object begins, starting the search at the specified position.long
position(byte[] pattern, long start)
Returns the position in thisSerialBlob
object where the given pattern of bytes begins, starting the search at the specified position.OutputStream
setBinaryStream(long pos)
Retrieves a stream that can be used to write to theBLOB
value that thisBlob
object represents.int
setBytes(long pos, byte[] bytes)
Writes the given array of bytes to theBLOB
value that thisBlob
object represents, starting at positionpos
, and returns the number of bytes written.int
setBytes(long pos, byte[] bytes, int offset, int length)
Writes all or part of the givenbyte
array to theBLOB
value that thisBlob
object represents and returns the number of bytes written.void
truncate(long length)
Truncates theBLOB
value that thisBlob
object represents to belen
bytes in length.
-
-
-
Constructor Detail
-
SerialBlob
public SerialBlob(byte[] b) throws SerialException, SQLException
Constructs aSerialBlob
object that is a serialized version of the givenbyte
array.The new
SerialBlob
object is initialized with the data from thebyte
array, thus allowing disconnectedRowSet
objects to establish serializedBlob
objects without touching the data source.- Parameters:
b
- thebyte
array containing the data for theBlob
object 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 aSerialBlob
object that is a serialized version of the givenBlob
object.The new
SerialBlob
object is initialized with the data from theBlob
object; therefore, theBlob
object should have previously brought the SQLBLOB
value's data over to the client from the database. Otherwise, the newSerialBlob
object will contain no data.- Parameters:
blob
- theBlob
object from which thisSerialBlob
object is to be constructed; cannot be null.- Throws:
SerialException
- if an error occurs during serializationSQLException
- if theBlob
passed to this to this constructor is anull
.- See Also:
Blob
-
-
Method Detail
-
getBytes
public byte[] getBytes(long pos, int length) throws SerialException
Copies the specified number of bytes, starting at the given position, from thisSerialBlob
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.- Specified by:
getBytes
in interfaceBlob
- Parameters:
pos
- the ordinal position of the first byte in thisSerialBlob
object to be copied; numbering starts at1
; must not be less than1
and must be less than or equal to the length of thisSerialBlob
objectlength
- the number of bytes to be copied- Returns:
- an array of bytes that is a copy of a region of this
SerialBlob
object, 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 SerialException
Retrieves the number of bytes in thisSerialBlob
object's array of bytes.- Specified by:
length
in interfaceBlob
- Returns:
- a
long
indicating the length in bytes of thisSerialBlob
object's array of bytes - Throws:
SerialException
- if an error occurs
-
getBinaryStream
public InputStream getBinaryStream() throws SerialException
Returns thisSerialBlob
object as an input stream. Unlike the related method,setBinaryStream
, a stream is produced regardless of whether theSerialBlob
was created with aBlob
object or abyte
array.- Specified by:
getBinaryStream
in interfaceBlob
- Returns:
- a
java.io.InputStream
object that contains thisSerialBlob
object's array of bytes - Throws:
SerialException
- if an error occurs- See Also:
setBinaryStream(long)
-
position
public long position(byte[] pattern, long start) throws SerialException, SQLException
Returns the position in thisSerialBlob
object where the given pattern of bytes begins, starting the search at the specified position.- Specified by:
position
in interfaceBlob
- Parameters:
pattern
- the pattern of bytes for which to searchstart
- the position of the byte in thisSerialBlob
object from which to begin the search; the first position is1
; must not be less than1
nor greater than the length of thisSerialBlob
object- Returns:
- the position in this
SerialBlob
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 at1
- Throws:
SerialException
- if an error occurs when serializing the blobSQLException
- if there is an error accessing theBLOB
value from the database
-
position
public long position(Blob pattern, long start) throws SerialException, SQLException
Returns the position in thisSerialBlob
object where the givenBlob
object begins, starting the search at the specified position.- Specified by:
position
in interfaceBlob
- Parameters:
pattern
- theBlob
object for which to search;start
- the position of the byte in thisSerialBlob
object from which to begin the search; the first position is1
; must not be less than1
nor greater than the length of thisSerialBlob
object- Returns:
- the position in this
SerialBlob
object where the givenBlob
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 at1
- Throws:
SerialException
- if an error occurs when serializing the blobSQLException
- if there is an error accessing theBLOB
value from the database
-
setBytes
public int setBytes(long pos, byte[] bytes) throws SerialException, SQLException
Writes the given array of bytes to theBLOB
value that thisBlob
object represents, starting at positionpos
, and returns the number of bytes written.- Specified by:
setBytes
in interfaceBlob
- Parameters:
pos
- the position in the SQLBLOB
value at which to start writing. The first position is1
; must not be less than1
nor greater than the length of thisSerialBlob
object.bytes
- the array of bytes to be written to theBLOB
value that thisBlob
object represents- Returns:
- the number of bytes written
- Throws:
SerialException
- if there is an error accessing theBLOB
value; or if an invalid position is set; if an invalid offset value is setSQLException
- if there is an error accessing theBLOB
value from the database- See Also:
getBytes(long, int)
-
setBytes
public int setBytes(long pos, byte[] bytes, int offset, int length) throws SerialException, SQLException
Writes all or part of the givenbyte
array to theBLOB
value that thisBlob
object represents and returns the number of bytes written. Writing starts at positionpos
in theBLOB
value; len bytes from the given byte array are written.- Specified by:
setBytes
in interfaceBlob
- Parameters:
pos
- the position in theBLOB
object at which to start writing. The first position is1
; must not be less than1
nor greater than the length of thisSerialBlob
object.bytes
- the array of bytes to be written to theBLOB
valueoffset
- the offset in thebyte
array at which to start reading the bytes. The first offset position is0
; must not be less than0
nor greater than the length of thebyte
arraylength
- the number of bytes to be written to theBLOB
value from the array of bytes bytes.- Returns:
- the number of bytes written
- Throws:
SerialException
- if there is an error accessing theBLOB
value; if an invalid position is set; if an invalid offset value is set; if number of bytes to be written is greater than theSerialBlob
length; or the combined values of the length and offset is greater than the Blob bufferSQLException
- if there is an error accessing theBLOB
value 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 theBLOB
value that thisBlob
object represents. The stream begins at positionpos
. This method forwards thesetBinaryStream()
call to the underlyingBlob
in the event that thisSerialBlob
object is instantiated with aBlob
. If thisSerialBlob
is instantiated with abyte
array, aSerialException
is thrown.- Specified by:
setBinaryStream
in interfaceBlob
- Parameters:
pos
- the position in theBLOB
value at which to start writing- Returns:
- a
java.io.OutputStream
object to which data can be written - Throws:
SQLException
- if there is an error accessing theBLOB
valueSerialException
- if the SerialBlob in not instantiated with aBlob
object that supportssetBinaryStream()
- See Also:
getBinaryStream()
-
truncate
public void truncate(long length) throws SerialException
Truncates theBLOB
value that thisBlob
object represents to belen
bytes in length.- Specified by:
truncate
in interfaceBlob
- Parameters:
length
- the length, in bytes, to which theBLOB
value that thisBlob
object 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 anInputStream
object that contains a partialBlob
value, starting with the byte specified by pos, which is length bytes in length.- Specified by:
getBinaryStream
in interfaceBlob
- Parameters:
pos
- the offset to the first byte of the partial value to be retrieved. The first byte in theBlob
is at position 1length
- the length in bytes of the partial value to be retrieved- Returns:
InputStream
through which the partialBlob
value can be read.- Throws:
SQLException
- if pos is less than 1 or if pos is greater than the number of bytes in theBlob
or if pos + length is greater than the number of bytes in theBlob
- Since:
- 1.6
-
free
public void free() throws SQLException
This method frees theBlob
object and releases the resources that it holds.Blob
object. The object is invalid once thefree
method is called. Iffree
is called multiple times, the subsequent calls tofree
are treated as a no-op.- Specified by:
free
in 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
17/11/2024 19:23:59 Cette version de la page est en cache (à la date du 17/11/2024 19:23:59) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version 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.