public class FBBlob extends java.lang.Object implements FirebirdBlob, Synchronizable
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 ResultSet,
CallableStatement, and 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.
FirebirdBlob.BlobInputStream, FirebirdBlob.BlobOutputStream| Modifier and Type | Field and Description |
|---|---|
static byte[] |
BLOB_LENGTH_REQUEST |
static int |
READ_FULLY_BUFFER_SIZE
Maximum blob segment size, see IB 6 Data Definition Guide, page 78 ("BLOB segment length")
|
static boolean |
SEGMENTED |
| Constructor and Description |
|---|
FBBlob(org.firebirdsql.gds.impl.GDSHelper c) |
FBBlob(org.firebirdsql.gds.impl.GDSHelper c,
FBObjectListener.BlobListener blobListener)
Create new Blob instance.
|
FBBlob(org.firebirdsql.gds.impl.GDSHelper c,
long blob_id)
Create instance of this class to access existing Blob.
|
FBBlob(org.firebirdsql.gds.impl.GDSHelper c,
long blob_id,
FBObjectListener.BlobListener blobListener)
Create instance of this class to access existing Blob.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this Blob object.
|
void |
copyBytes(byte[] bytes,
int pos,
int len) |
void |
copyCharacterStream(java.io.Reader inputStream,
int length,
java.lang.String encoding)
Copy data from a character stream into this Blob.
|
void |
copyStream(java.io.InputStream inputStream)
Copy the contents of an
InputStream into this Blob. |
void |
copyStream(java.io.InputStream inputStream,
int length)
Copy the contents of an
InputStream into this Blob. |
FirebirdBlob |
detach()
Detach this blob.
|
void |
free()
This method frees the
Blob object and releases the resources that
it holds. |
java.io.InputStream |
getBinaryStream()
Retrieves the
BLOB designated by this
Blob instance as a stream. |
java.io.InputStream |
getBinaryStream(long pos,
long length)
Returns an
InputStream object that contains a partial Blob value,
starting with the byte specified by pos, which is length bytes in length. |
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.
|
java.lang.Object |
getSynchronizationObject()
Get synchronization object.
|
static long |
interpretLength(org.firebirdsql.gds.impl.GDSHelper gdsHelper,
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(java.sql.Blob pattern,
long start)
Determines the byte position in the
BLOB value
designated by this Blob object at which
pattern begins. |
long |
position(byte[] pattern,
long start)
Determines the byte position at which the specified byte
pattern begins within the BLOB
value that this Blob object represents. |
java.io.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. |
public static final boolean SEGMENTED
public static final int READ_FULLY_BUFFER_SIZE
public static final byte[] BLOB_LENGTH_REQUEST
public FBBlob(org.firebirdsql.gds.impl.GDSHelper c,
FBObjectListener.BlobListener blobListener)
c - connection that will be used to write data to blob.public FBBlob(org.firebirdsql.gds.impl.GDSHelper c)
public FBBlob(org.firebirdsql.gds.impl.GDSHelper c,
long blob_id,
FBObjectListener.BlobListener blobListener)
c - connection that will be used to access Blob.blob_id - ID of the Blob.blobListener - Blob listener instancepublic FBBlob(org.firebirdsql.gds.impl.GDSHelper c,
long blob_id)
c - connection that will be used to access Blob.blob_id - ID of the Blob.public final java.lang.Object getSynchronizationObject()
SynchronizablegetSynchronizationObject in interface Synchronizablenull.public void close()
throws java.io.IOException
java.io.IOException - if at least one of the stream raised an exception
when closed.public void free()
throws java.sql.SQLException
Blob object and releases the resources that
it holds. The object is invalid once the free
method is called.
After free has been called, any attempt to invoke a
method other than free will result in a SQLException
being thrown. If free is called multiple times, the subsequent
calls to free are treated as a no-op.
free in interface java.sql.Blobjava.sql.SQLException - if an error occurs releasing
the Blob's resourcesjava.sql.SQLFeatureNotSupportedException - if the JDBC driver does not support
this methodpublic java.io.InputStream getBinaryStream(long pos,
long length)
throws java.sql.SQLException
InputStream object that contains a partial Blob value,
starting with the byte specified by pos, which is length bytes in length.getBinaryStream in interface java.sql.Blobpos - the offset to the first byte of the partial value to be retrieved.
The first byte in the Blob is at position 1length - the length in bytes of the partial value to be retrievedInputStream through which the partial Blob value can be read.java.sql.SQLException - if pos is less than 1 or if pos is greater than the number of bytes
in the Blob or if pos + length is greater than the number of bytes
in the Blobjava.sql.SQLFeatureNotSupportedException - if the JDBC driver does not support
this methodpublic byte[] getInfo(byte[] items,
int buffer_length)
throws java.sql.SQLException
items - items in which we are interested.buffer_length - buffer where information will be stored.java.sql.SQLException - if something went wrong.public long length()
throws java.sql.SQLException
BLOB value
designated by this Blob object.length in interface java.sql.BlobBLOB in bytesjava.sql.SQLException - if there is an error accessing the
length of the BLOBpublic static long interpretLength(org.firebirdsql.gds.impl.GDSHelper gdsHelper,
byte[] info,
int position)
throws java.sql.SQLException
info - server response.position - where to start interpreting.java.sql.SQLException - if length cannot be interpreted.public boolean isSegmented()
throws java.sql.SQLException
isSegmented in interface FirebirdBlobtrue if this blob is segmented,
otherwise falsejava.sql.SQLException - if something went wrong.public FirebirdBlob detach() throws java.sql.SQLException
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 FirebirdBlobFBBlob that is not under result set control.java.sql.SQLException - if Blob cannot be detached.public byte[] getBytes(long pos,
int length)
throws java.sql.SQLException
BLOB
value that this Blob object designates. The byte
array contains up to length consecutive bytes
starting at position pos.getBytes in interface java.sql.Blobpos - 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 copiedlength
consecutive bytes from the BLOB value designated
by this Blob object, starting with the
byte at position posjava.sql.SQLException - if there is an error accessing the
BLOBpublic java.io.InputStream getBinaryStream()
throws java.sql.SQLException
BLOB designated by this
Blob instance as a stream.getBinaryStream in interface java.sql.BlobBLOB datajava.sql.SQLException - if there is an error accessing the
BLOBpublic long position(byte[] pattern,
long start)
throws java.sql.SQLException
pattern begins within the BLOB
value that this Blob object represents. The
search for pattern begins at position
start.position in interface java.sql.Blobpattern - the byte array for which to searchstart - the position at which to begin searching; the
first position is 1java.sql.SQLException - if there is an error accessing the
BLOBpublic long position(java.sql.Blob pattern,
long start)
throws java.sql.SQLException
BLOB value
designated by this Blob object at which
pattern begins. The search begins at position
start.position in interface java.sql.Blobpattern - 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 1java.sql.SQLException - if there is an error accessing the
BLOBpublic void truncate(long param1)
throws java.sql.SQLException
Blob to a given length.truncate in interface java.sql.Blobparam1 - The length to truncate this Blob tojava.sql.SQLException - this operation is not supportedpublic int setBytes(long param1,
byte[] param2)
throws java.sql.SQLException
Blob object represents and returns the number of bytes
written.setBytes in interface java.sql.Blobparam1 - The position at which to start writingparam2 - The array of bytes to be writtenjava.sql.SQLException - because this operation is not supportedpublic int setBytes(long param1,
byte[] param2,
int param3,
int param4)
throws java.sql.SQLException
Blob object represents and returns the number of bytes
written.setBytes in interface java.sql.Blobparam1 - 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 arrayjava.sql.SQLException - because this operation is not supportedpublic java.io.OutputStream setBinaryStream(long pos)
throws java.sql.SQLException
setBinaryStream in interface java.sql.BlobsetBinaryStream in interface FirebirdBlobpos - The position in the blob to start writing.java.sql.SQLException - if a database access error occurspublic long getBlobId()
throws java.sql.SQLException
BlobBlob's identifierjava.sql.SQLException - if a database access error occurspublic void copyBytes(byte[] bytes,
int pos,
int len)
throws java.sql.SQLException
java.sql.SQLExceptionpublic void copyStream(java.io.InputStream inputStream,
int length)
throws java.sql.SQLException
InputStream into this Blob.inputStream - the stream from which data will be copiedlength - The maximum number of bytes to read from the InputStreamjava.sql.SQLException - if a database access error occurspublic void copyStream(java.io.InputStream inputStream)
throws java.sql.SQLException
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 copiedjava.sql.SQLException - if a database access error occurspublic void copyCharacterStream(java.io.Reader inputStream,
int length,
java.lang.String encoding)
throws java.sql.SQLException
inputStream - the source of data to copylength - The maximum number of bytes to copyencoding - The encoding used in the character streamjava.sql.SQLExceptionCopyright © 2001-2019 Jaybird (Firebird JDBC/JCA) team. All rights reserved.