org.firebirdsql.jdbc

Class FBBlob

Implemented Interfaces:
Blob, FirebirdBlob, Synchronizable

public class FBBlob
extends java.lang.Object
implements FirebirdBlob, Synchronizable

The representation (mapping) in the JavaTM 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.

Since:
1.2

Nested Class Summary

class
FBBlob.FBBlobInputStream
An input stream for reading directly from a FBBlob instance.
class
FBBlob.FBBlobOutputStream

Field Summary

static byte[]
BLOB_LENGTH_REQUEST
static int
READ_FULLY_BUFFER_SIZE
static boolean
SEGMENTED

Constructor Summary

FBBlob(org.firebirdsql.gds.impl.GDSHelper c)
FBBlob(org.firebirdsql.gds.impl.GDSHelper c, long blob_id)
FBBlob(org.firebirdsql.gds.impl.GDSHelper c, long blob_id, FBObjectListener.BlobListener blobListener)
Create instance of this class to access existing Blob.
FBBlob(org.firebirdsql.gds.impl.GDSHelper c, FBObjectListener.BlobListener blobListener)
Create new Blob instance.

Method Summary

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.

Field Details

BLOB_LENGTH_REQUEST

public static final byte[] BLOB_LENGTH_REQUEST

READ_FULLY_BUFFER_SIZE

public static final int READ_FULLY_BUFFER_SIZE
Field Value:
16384

SEGMENTED

public static final boolean SEGMENTED
Field Value:
true

Constructor Details

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.
Parameters:
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.
Parameters:
c - connection that will be used to write data to blob.

Method Details

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.
Parameters:
inputStream - the source of data to copy
length - The maximum number of bytes to copy
encoding - The encoding used in the character stream

copyStream

public void copyStream(InputStream inputStream)
            throws SQLException
Parameters:
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.
Parameters:
inputStream - the stream from which data will be copied
length - 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.

Specified by:
detach in interface FirebirdBlob
Returns:
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.
Returns:
a stream containing the BLOB data
Since:
1.2

getBlobId

public long getBlobId()
            throws SQLException
Get the identifier for this Blob
Returns:
This Blob's identifier

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.
Parameters:
pos - the ordinal position of the first byte in the BLOB value to be extracted; the first byte is at position 1
length - the number of consecutive bytes to be copied
Returns:
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
Since:
1.2

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".
Parameters:
items - items in which we are interested.
buffer_length - buffer where information will be stored.
Returns:
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.
Specified by:
getSynchronizationObject in interface Synchronizable
Returns:
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.
Parameters:
info - server response.
position - where to start interpreting.
Returns:
length of the blob.

isSegmented

public boolean isSegmented()
            throws SQLException
Check if blob is segmented.
Specified by:
isSegmented in interface FirebirdBlob
Returns:
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.
Returns:
length of the BLOB in bytes
Since:
1.2

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.
Parameters:
pattern - the Blob object designating the BLOB value for which to search
start - the position in the BLOB value at which to begin searching; the first position is 1
Returns:
the position at which the pattern begins, else -1
Since:
1.2

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.
Parameters:
start - the position at which to begin searching; the first position is 1
Returns:
the position at which the pattern appears, else -1
Since:
1.2

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.
Specified by:
setBinaryStream in interface FirebirdBlob
Parameters:
pos - The position in the blob to start writing.
Returns:
OuputStream to write to.

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.
Parameters:
param1 - The position at which to start writing
param2 - The array of bytes to be written
Returns:
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.
Parameters:
param1 - The position at which to start writing
param2 - The array of bytes to be written
param3 - the offset into the byte array at which to start reading the bytes to be set
param4 - the number of bytes to be written to the BLOB value from the byte array
Returns:
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.
Parameters:
param1 - The length to truncate this Blob to

Copyright B) 2001 David Jencks and other authors. All rights reserved.