org.firebirdsql.jdbc
Class FBBlob
java.lang.Object
org.firebirdsql.jdbc.FBBlob
- Blob, FirebirdBlob, Synchronizable
public class FBBlob
extends java.lang.Object
The representation (mapping) in
the Java
TM programming
language of an SQL
BLOB
value. An SQL
BLOB
is a built-in type
that stores a Binary Large Object as a column value in a row of
a database table. The driver implements
Blob
using
an SQL
locator(BLOB)
, which means that a
Blob
object contains a logical pointer to the
SQL
BLOB
data rather than the data itself.
A
Blob
object is valid for the duration of the
transaction in which is was created.
Methods in the interfaces
java.sql.ResultSet
,
java.sql.CallableStatement
, and
java.sql.PreparedStatement
, such as
getBlob
and
setBlob
allow a programmer to
access an SQL
BLOB
value.
The
Blob
interface provides methods for getting the
length of an SQL
BLOB
(Binary Large Object) value,
for materializing a
BLOB
value on the client, and for
determining the position of a pattern of bytes within a
BLOB
value.
This class is new in the JDBC 2.0 API.
void | close() - Close this Blob object.
|
void | copyBytes(byte[] bytes, int pos, int len)
|
void | copyCharacterStream(Reader inputStream, int length, String encoding) - Copy data from a character stream into this Blob.
|
void | copyStream(InputStream inputStream) - Copy the contents of an
InputStream into this Blob.
|
void | copyStream(InputStream inputStream, int length) - Copy the contents of an
InputStream into this Blob.
|
FirebirdBlob | detach() - Detach this blob.
|
InputStream | getBinaryStream() - Retrieves the
BLOB designated by this
Blob instance as a stream.
|
long | getBlobId() - Get the identifier for this
Blob
|
byte[] | getBytes(long pos, int length) - Returns as an array of bytes, part or all of the
BLOB
value that this Blob object designates.
|
byte[] | getInfo(byte[] items, int buffer_length) - Get information about this Blob.
|
Object | getSynchronizationObject() - Get synchronization object that will be used to synchronize multithreaded
access to the database.
|
static long | interpretLength(GDS gds, byte[] info, int position) - Interpret BLOB length from buffer.
|
boolean | isSegmented() - Check if blob is segmented.
|
long | length() - Returns the number of bytes in the
BLOB value
designated by this Blob object.
|
long | position(Blob pattern, long start) - Determines the byte position in the
BLOB value
designated by this Blob object at which
pattern begins.
|
long | position(pattern[] , long start) - Determines the byte position at which the specified byte
pattern begins within the BLOB
value that this Blob object represents.
|
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 param1, byte[] param2) - This operation is not currently supported
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.
|
int | setBytes(long param1, byte[] param2, int param3, int param4) - This operation is not currently supported
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 param1) - This operation is not currently supported
Truncate this
Blob to a given length.
|
BLOB_LENGTH_REQUEST
public static final byte[] BLOB_LENGTH_REQUEST
READ_FULLY_BUFFER_SIZE
public static final int READ_FULLY_BUFFER_SIZE
SEGMENTED
public static final boolean SEGMENTED
FBBlob
public FBBlob(org.firebirdsql.gds.impl.GDSHelper c)
FBBlob
public FBBlob(org.firebirdsql.gds.impl.GDSHelper c,
long blob_id)
FBBlob
public FBBlob(org.firebirdsql.gds.impl.GDSHelper c,
long blob_id,
FBObjectListener.BlobListener blobListener)
Create instance of this class to access existing Blob.
c
- connection that will be used to access Blob.blob_id
- ID of the Blob.
FBBlob
public FBBlob(org.firebirdsql.gds.impl.GDSHelper c,
FBObjectListener.BlobListener blobListener)
Create new Blob instance. This constructor creates new fresh Blob, only
writing to the Blob is allowed.
c
- connection that will be used to write data to blob.
close
public void close()
throws IOException
Close this Blob object. This method closes all open input streams.
copyBytes
public void copyBytes(byte[] bytes,
int pos,
int len)
throws SQLException
copyCharacterStream
public void copyCharacterStream(Reader inputStream,
int length,
String encoding)
throws SQLException
Copy data from a character stream into this Blob.
inputStream
- the source of data to copylength
- The maximum number of bytes to copyencoding
- The encoding used in the character stream
copyStream
public void copyStream(InputStream inputStream)
throws SQLException
Copy the contents of an
InputStream
into this Blob. Unlike
the
copyStream(InputStream,int)
method, this one copies bytes
until the EOF is reached.
inputStream
- the stream from which data will be copied
copyStream
public void copyStream(InputStream inputStream,
int length)
throws SQLException
Copy the contents of an InputStream
into this Blob.
inputStream
- the stream from which data will be copiedlength
- The maximum number of bytes to read from the InputStream
detach
public FirebirdBlob detach()
throws SQLException
Detach this blob. This method creates new instance of the same blob
database object that is not under result set control. When result set
is closed, all associated resources are also released, including open
blob streams. This method creates an new instance of blob object with
the same blob ID that can be used even when result set is closed.
Note, detached blob will not remember the stream position of this object.
This means that you cannot start reading data from the blob, then detach
it, and then continue reading. Reading from detached blob will begin at
the blob start.
- detach in interface FirebirdBlob
- instance of
FBBlob
that is not under result set control.
getBinaryStream
public InputStream getBinaryStream()
throws SQLException
Retrieves the BLOB
designated by this
Blob
instance as a stream.
- a stream containing the
BLOB
data
getBlobId
public long getBlobId()
throws SQLException
Get the identifier for this Blob
getBytes
public byte[] getBytes(long pos,
int length)
throws SQLException
Returns as an array of bytes, part or all of the BLOB
value that this Blob
object designates. The byte
array contains up to length
consecutive bytes
starting at position pos
.
pos
- the ordinal position of the first byte in the
BLOB
value to be extracted; the first byte is at
position 1length
- the number of consecutive bytes to be copied
- a byte array containing up to
length
consecutive bytes from the BLOB
value designated
by this Blob
object, starting with the
byte at position pos
getInfo
public byte[] getInfo(byte[] items,
int buffer_length)
throws SQLException
Get information about this Blob. This method should be considered as
temporary because it provides access to low-level API. More information
on how to use the API can be found in "API Guide".
items
- items in which we are interested.buffer_length
- buffer where information will be stored.
- array of bytes containing information about this Blob.
getSynchronizationObject
public Object getSynchronizationObject()
Get synchronization object that will be used to synchronize multithreaded
access to the database.
- getSynchronizationObject in interface Synchronizable
- object that will be used for synchronization.
interpretLength
public static long interpretLength(GDS gds,
byte[] info,
int position)
throws SQLException
Interpret BLOB length from buffer.
info
- server response.position
- where to start interpreting.
isSegmented
public boolean isSegmented()
throws SQLException
Check if blob is segmented.
- isSegmented in interface FirebirdBlob
true
if this blob is segmented,
otherwise false
length
public long length()
throws SQLException
Returns the number of bytes in the BLOB
value
designated by this Blob
object.
- length of the
BLOB
in bytes
position
public long position(Blob pattern,
long start)
throws SQLException
Determines the byte position in the BLOB
value
designated by this Blob
object at which
pattern
begins. The search begins at position
start
.
pattern
- the Blob
object designating
the BLOB
value for which to searchstart
- the position in the BLOB
value
at which to begin searching; the first position is 1
- the position at which the pattern begins, else -1
position
public long position(pattern[] ,
long start)
throws SQLException
Determines the byte position at which the specified byte
pattern
begins within the BLOB
value that this Blob
object represents. The
search for pattern
begins at position
start
.
start
- the position at which to begin searching; the
first position is 1
- the position at which the pattern appears, else -1
setBinaryStream
public OutputStream setBinaryStream(long pos)
throws SQLException
Retrieves a stream that can be used to write to the BLOB value that
this Blob object represents. The stream begins at position pos.
- setBinaryStream in interface FirebirdBlob
pos
- The position in the blob to start writing.
setBytes
public int setBytes(long param1,
byte[] param2)
throws SQLException
This operation is not currently supported
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.
param1
- The position at which to start writingparam2
- The array of bytes to be written
- the number of bytes written
setBytes
public int setBytes(long param1,
byte[] param2,
int param3,
int param4)
throws SQLException
This operation is not currently supported
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.
param1
- The position at which to start writingparam2
- The array of bytes to be writtenparam3
- the offset into the byte array at which to start reading
the bytes to be setparam4
- the number of bytes to be written to the BLOB value from
the byte array
- the number of bytes written
truncate
public void truncate(long param1)
throws SQLException
This operation is not currently supported
Truncate this Blob
to a given length.
param1
- The length to truncate this Blob to
Copyright B) 2001 David Jencks and other authors. All rights reserved.