java.lang.Objectjavax.sql.rowset.serial.SerialBlob
A serializable mapping in the Java programming language of an SQL
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.
| Constructor Summary | |
|---|---|
SerialBlob(Blob blob)
Constructs a SerialBlob object that is a serializable
version of the given Blob object. |
|
| Method Summary | |
|---|---|
InputStream |
getBinaryStream()
Returns this SerialBlob object as an input stream. |
byte[] |
getBytes(long pos,
int length)
Copies the specified number of bytes, starting at the given position, from this SerialBlob object to
another array of bytes. |
long |
length()
Retrieves the number of bytes in this SerialBlob
object's array of bytes. |
long |
position(Blob pattern,
long start)
Returns the position in this SerialBlob object where
the given Blob object begins, starting the search at the
specified position. |
long |
position(byte[] pattern,
long start)
Returns the position in this SerialBlob 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 the BLOB
value that this Blob object represents. |
int |
setBytes(long pos,
byte[] bytes)
Writes the given array of bytes to the BLOB value that
this Blob object represents, starting at position
pos, and returns the number of bytes written. |
int |
setBytes(long pos,
byte[] bytes,
int offset,
int length)
Writes all or part of the given byte array to the
BLOB value that this Blob object represents
and returns the number of bytes written. |
void |
truncate(long length)
Truncates the BLOB value that this Blob
object represents to be len bytes in length. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SerialBlob(Blob blob)
throws SerialException,
SQLException
SerialBlob object that is a serializable
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
SerialException - if an error occurs
SQLExceptionBlob| Method Detail |
|---|
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 Blobpos - the ordinal position of the first byte in this
SerialBlob object to be copied;
numbering starts at 0; must not be less
than 0 and must be less than or equal
to the length of this SerialBlob objectlength - the number of bytes to be copied
SerialBlob object, starting at the given
position and containing the given number of consecutive bytes
SerialException - if the given starting position is out of boundsBlob.setBytes(long, byte[])
public long length()
throws SerialException
SerialBlob
object's array of bytes.
length in interface Bloblong indicating the length in bytes of this
SerialBlob object's array of bytes
SerialException - if an error occurs
public InputStream getBinaryStream()
throws SerialException
SerialBlob object as an input stream.
getBinaryStream in interface Blobjava.io.InputStream object that contains
this SerialBlob object's array of bytes
SerialException - if an error occursBlob.setBinaryStream(long)
public 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 Blobpattern - the pattern of bytes 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 object
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 at 1
SerialException - if an error occurs to serialise the blob.
SQLException - if there is an error accessing the Blob value
from the database.
public 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 Blobpattern - 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 0;
must not be less than 0 nor greater than
the length of this SerialBlob object
SerialBlob 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
SQLException - if there is an error accessing the
BLOB value
public int setBytes(long pos,
byte[] bytes)
throws SerialException
BLOB value that
this Blob object represents, starting at position
pos, and returns the number of bytes written.
setBytes in interface Blobpos - the position in the BLOB object at which
to start writingbytes - the array of bytes to be written to the BLOB
value that this Blob object represents
SQLException - if there is an error accessing the
BLOB value
SerialExceptiongetBytes(long, int)
public int setBytes(long pos,
byte[] bytes,
int offset,
int length)
throws SerialException
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; len bytes from the given byte array are written.
setBytes in interface Blobpos - the position in the BLOB object at which
to start writingbytes - the array of bytes to be written to this BLOB
objectoffset - the offset into the array bytes at which
to start reading the bytes to be setlength - the number of bytes to be written to the
BLOB
value from the array of bytes bytes
SQLException - if there is an error accessing the
BLOB value
SerialExceptiongetBytes(long, int)
public OutputStream setBinaryStream(long pos)
throws SerialException
BLOB
value that this Blob object represents. The stream begins
at position pos.
setBinaryStream in interface Blobpos - the position in the BLOB value at which
to start writing
java.io.OutputStream object to which data can
be written
SQLException - if there is an error accessing the
BLOB value
SerialExceptiongetBinaryStream()
public void truncate(long length)
throws SerialException
BLOB value that this Blob
object represents to be len bytes in length.
truncate in interface Bloblength - the length, in bytes, to which the BLOB
value that this Blob object represents should be
truncated
SQLException - if there is an error accessing the
BLOB value
SerialException