## org.firebirdsql.jdbc
Class FBBlob

    java.lang.Object
      org.firebirdsql.jdbc.FBBlob

All Implemented Interfaces:
  Blob, FirebirdBlob, Synchronizable

    public class FBBlob

extends 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 `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.

Since:
  1.2

Nested Class Summary
`class` `FBBlob.FBBlobInputStream` An input stream for reading directly from a FBBlob instance.
`class` `FBBlob.FBBlobOutputStream`

Nested classes/interfaces inherited from interface org.firebirdsql.jdbc.FirebirdBlob
`FirebirdBlob.BlobInputStream, FirebirdBlob.BlobOutputStream`

Field Summary
`static byte[]` `BLOB_LENGTH_REQUEST`
`static int` `READ_FULLY_BUFFER_SIZE`
`static boolean` `SEGMENTED`

Constructor Summary
`FBBlob(GDSHelper c)`
`FBBlob(GDSHelper c, FBObjectListener.BlobListener blobListener)` Create new Blob instance.
`FBBlob(GDSHelper c, long blob_id)`
`FBBlob(GDSHelper c, long blob_id, FBObjectListener.BlobListener blobListener)` Create instance of this class to access existing Blob.

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.
`void` `free()`
`InputStream` `getBinaryStream()` Retrieves the `BLOB` designated by this `Blob` instance as a stream.
`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.
`Object` `getSynchronizationObject()` Get synchronization object that will be used to synchronize multithreaded access to the database.
`static long` `interpretLength(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(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.
`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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### SEGMENTED

    public static final boolean SEGMENTED

See Also:
  Constant Field Values

### READ_FULLY_BUFFER_SIZE

    public static final int READ_FULLY_BUFFER_SIZE

See Also:
  Constant Field Values

### BLOB_LENGTH_REQUEST

    public static final byte[] BLOB_LENGTH_REQUEST

Constructor Detail

### FBBlob

    public FBBlob(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.

### FBBlob

    public FBBlob(GDSHelper c)

### FBBlob

    public FBBlob(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(GDSHelper c,
                  long blob_id)

Method Detail

### 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.

### close

    public void close()
               throws IOException

  Close this Blob object. This method closes all open input streams.

  Throws:
    `IOException` - if at least one of the stream raised an exception when closed.

### 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.
  Throws:
    `SQLException` - if something went wrong.

### length

    public long length()
                throws SQLException

  Returns the number of bytes in the `BLOB` value designated by this `Blob` object.

  Specified by:
    `length` in interface `Blob`
  Returns:
    length of the `BLOB` in bytes
  Throws:
    `SQLException` - if there is an error accessing the length of the `BLOB`
  Since:
    1.2
  See Also:
    What Is in the JDBC 2.0 API

### interpretLength

    public static long interpretLength(GDSHelper gdsHelper,
                                       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.
  Throws:
    `SQLException` - if length cannot be interpreted.

### 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`
  Throws:
    `SQLException` - if something went wrong.

### 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.
  Throws:
    `SQLException` - if Blob cannot be detached.

### 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`.

  Specified by:
    `getBytes` in interface `Blob`
  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`
  Throws:
    `SQLException` - if there is an error accessing the `BLOB`
  Since:
    1.2
  See Also:
    What Is in the JDBC 2.0 API

### getBinaryStream

    public InputStream getBinaryStream()
                                throws SQLException

  Retrieves the `BLOB` designated by this `Blob` instance as a stream.

  Specified by:
    `getBinaryStream` in interface `Blob`
  Returns:
    a stream containing the `BLOB` data
  Throws:
    `SQLException` - if there is an error accessing the `BLOB`
  Since:
    1.2
  See Also:
    What Is in the JDBC 2.0 API

### position

    public long position(byte[] 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`.

  Specified by:
    `position` in interface `Blob`
  Parameters:
    `pattern` - the byte array for which to search
    `start` - the position at which to begin searching; the first position is 1
  Returns:
    the position at which the pattern appears, else -1
  Throws:
    `SQLException` - if there is an error accessing the `BLOB`
  Since:
    1.2
  See Also:
    What Is in the JDBC 2.0 API

### 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`.

  Specified by:
    `position` in interface `Blob`
  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
  Throws:
    `SQLException` - if there is an error accessing the `BLOB`
  Since:
    1.2
  See Also:
    What Is in the JDBC 2.0 API

### truncate

    public void truncate(long param1)
                  throws SQLException

  This operation is not currently supported Truncate this `Blob` to a given length.

  Specified by:
    `truncate` in interface `Blob`
  Parameters:
    `param1` - The length to truncate this Blob to
  Throws:
    `SQLException` - this operation is not supported

### 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.

  Specified by:
    `setBytes` in interface `Blob`
  Parameters:
    `param1` - The position at which to start writing
    `param2` - The array of bytes to be written
  Returns:
    the number of bytes written
  Throws:
    `SQLException` - because this operation is not supported

### 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.

  Specified by:
    `setBytes` in interface `Blob`
  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
  Throws:
    `SQLException` - because this operation is not supported

### 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 `Blob`
  Specified by:
    `setBinaryStream` in interface `FirebirdBlob`
  Parameters:
    `pos` - The position in the blob to start writing.
  Returns:
    OuputStream to write to.
  Throws:
    `SQLException` - if a database access error occurs

### getBlobId

    public long getBlobId()
                   throws SQLException

  Get the identifier for this `Blob`

  Returns:
    This `Blob`'s identifier
  Throws:
    `SQLException` - if a database access error occurs

### copyBytes

    public void copyBytes(byte[] bytes,
                          int pos,
                          int len)
                   throws SQLException

  Throws:
    `SQLException`

### 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
  Throws:
    `SQLException` - if a database access error occurs

### 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.

  Parameters:
    `inputStream` - the stream from which data will be copied
  Throws:
    `SQLException` - if a database access error occurs

### 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
  Throws:
    `SQLException`

### free

    public void free()
              throws SQLException

  Specified by:
    `free` in interface `Blob`
  Throws:
    `SQLException`

### getBinaryStream

    public InputStream getBinaryStream(long pos,
                                       long length)
                                throws SQLException

  Returns an `InputStream` object that contains a partial `Blob` value, starting with the byte specified by pos, which is length bytes in length.

  Specified by:
    `getBinaryStream` in interface `Blob`
  Parameters:
    `pos` - the offset to the first byte of the partial value to be retrieved. The first byte in the `Blob` is at position 1
    `length` - the length in bytes of the partial value to be retrieved
  Returns:
    `InputStream` through which the partial `Blob` value can be read.
  Throws:
    `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 `Blob`
    `SQLFeatureNotSupportedException` - if the JDBC driver does not support this method
  Since:
    1.6

Copyright © 2001-2010. All Rights Reserved.