org.firebirdsql.jdbc

## Class FBBlob

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

- All Implemented Interfaces:
    java.sql.Blob, TransactionListener, FirebirdBlob

      public final class FBBlob
      extends java.lang.Object
      implements FirebirdBlob, TransactionListener

  Firebird implementation of `Blob`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `FBBlob.Config` Standard configuration for blobs.

    - ### Nested classes/interfaces inherited from interface org.firebirdsql.jdbc.FirebirdBlob

      `FirebirdBlob.BlobInputStream, FirebirdBlob.BlobOutputStream`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FBBlob(GDSHelper c)` Deprecated. will be removed in Jaybird 6, use `FBBlob(GDSHelper, FBObjectListener.BlobListener, Config)`
    `FBBlob(GDSHelper c, FBObjectListener.BlobListener blobListener)` Deprecated. will be removed in Jaybird 6, use `FBBlob(GDSHelper, FBObjectListener.BlobListener, Config)`
    `FBBlob(GDSHelper c, FBObjectListener.BlobListener blobListener, FBBlob.Config config)` Create new Blob instance.
    `FBBlob(GDSHelper c, long blobId)` Deprecated. will be removed in Jaybird 6, use `FBBlob(GDSHelper, long, FBObjectListener.BlobListener, Config)`
    `FBBlob(GDSHelper c, long blobId, FBObjectListener.BlobListener blobListener)` Deprecated. will be removed in Jaybird 6, use `FBBlob(GDSHelper, long, FBObjectListener.BlobListener, Config)`
    `FBBlob(GDSHelper c, long blobId, FBObjectListener.BlobListener blobListener, FBBlob.Config config)` Create instance of this class to access existing Blob.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `copyBytes(byte[] bytes, int pos, int len)`
    `void` | `copyCharacterStream(java.io.Reader reader)` Copy data from a character stream into this Blob.
    `void` | `copyCharacterStream(java.io.Reader reader, Encoding encoding)` Copy data from a character stream into this Blob.
    `void` | `copyCharacterStream(java.io.Reader reader, long length)` Copy data from a character stream into this Blob.
    `void` | `copyCharacterStream(java.io.Reader reader, long length, Encoding 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, long length)` Copy the contents of an `InputStream` into this Blob.
    `static FBBlob.Config` | `createConfig(FieldDescriptor fieldDescriptor, DatabaseConnectionProperties connectionProperties)` Creates a blob configuration from a field descriptor and connection properties.
    `static FBBlob.Config` | `createConfig(int subType, boolean useStreamBlob, int blobBufferSize, DatatypeCoder datatypeCoder)` Create a blob configuration.
    `static FBBlob.Config` | `createConfig(int subType, DatabaseConnectionProperties connectionProperties, DatatypeCoder datatypeCoder)` Creates a blob configuration from a subtype and connection properties and datatype coder.
    `FirebirdBlob` | `detach()` Detach this blob.
    `void` | `free()`
    `java.io.InputStream` | `getBinaryStream()`
    `java.io.InputStream` | `getBinaryStream(long pos, long length)`
    `long` | `getBlobId()` Get the identifier for this `Blob`
    `byte[]` | `getBytes(long pos, int length)`
    `byte[]` | `getInfo(byte[] items, int buffer_length)` Get information about this Blob.
    `boolean` | `isSegmented()` Check if blob is segmented.
    `long` | `length()`
    `long` | `position(java.sql.Blob pattern, long start)`
    `long` | `position(byte[] pattern, long start)`
    `java.io.OutputStream` | `setBinaryStream(long pos)`
    `int` | `setBytes(long pos, byte[] bytes)`
    `int` | `setBytes(long pos, byte[] bytes, int offset, int len)`
    `void` | `transactionStateChanged(FbTransaction transaction, TransactionState newState, TransactionState previousState)` Signals that the transaction state changed.
    `void` | `truncate(long len)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FBBlob

          @Deprecated
          public FBBlob(GDSHelper c,
                                     FBObjectListener.BlobListener blobListener)

      Deprecated. will be removed in Jaybird 6, use `FBBlob(GDSHelper, FBObjectListener.BlobListener, Config)`
      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
        `blobListener` - Blob listener instance

    - #### FBBlob

          public FBBlob(GDSHelper c,
                        FBObjectListener.BlobListener blobListener,
                        FBBlob.Config config)

      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
        `blobListener` - Blob listener instance
        `config` - blob configuration (`null` allowed in Jaybird 5, will be disallowed in Jaybird 6)
      Since:
        5

    - #### FBBlob

          @Deprecated
          public FBBlob(GDSHelper c)

      Deprecated. will be removed in Jaybird 6, use `FBBlob(GDSHelper, FBObjectListener.BlobListener, Config)`
      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

          @Deprecated
          public FBBlob(GDSHelper c,
                                     long blobId,
                                     FBObjectListener.BlobListener blobListener)

      Deprecated. will be removed in Jaybird 6, use `FBBlob(GDSHelper, long, FBObjectListener.BlobListener, Config)`
      Create instance of this class to access existing Blob.
      Parameters:
        `c` - connection that will be used to access Blob.
        `blobId` - ID of the Blob.
        `blobListener` - blob listener instance

    - #### FBBlob

          public FBBlob(GDSHelper c,
                        long blobId,
                        FBObjectListener.BlobListener blobListener,
                        FBBlob.Config config)

      Create instance of this class to access existing Blob.
      Parameters:
        `c` - connection that will be used to access Blob.
        `blobId` - ID of the Blob.
        `blobListener` - blob listener instance
        `config` - blob configuration (`null` allowed in Jaybird 5, will be disallowed in Jaybird 6)
      Since:
        5

    - #### FBBlob

          @Deprecated
          public FBBlob(GDSHelper c,
                                     long blobId)

      Deprecated. will be removed in Jaybird 6, use `FBBlob(GDSHelper, long, FBObjectListener.BlobListener, Config)`
      Create instance of this class to access existing Blob.
      Parameters:
        `c` - connection that will be used to access Blob.
        `blobId` - ID of the Blob.

  - ### Method Detail

    - #### free

          public void free()
                    throws java.sql.SQLException

      Specified by:
        `free` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### getBinaryStream

          public java.io.InputStream getBinaryStream(long pos,
                                                     long length)
                                              throws java.sql.SQLException

      Specified by:
        `getBinaryStream` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### getInfo

          public byte[] getInfo(byte[] items,
                                int buffer_length)
                         throws java.sql.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:
        `java.sql.SQLException` - if something went wrong.

    - #### length

          public long length()
                      throws java.sql.SQLException

      Specified by:
        `length` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### isSegmented

          public boolean isSegmented()
                              throws java.sql.SQLException

      Description copied from interface: `FirebirdBlob`
      Check if blob is segmented. If Blob is segmented, you cannot use `FirebirdBlob.BlobInputStream.seek(int)` method.
      Specified by:
        `isSegmented` in interface `FirebirdBlob`
      Returns:
        `true` if this blob is segmented, otherwise `false`
      Throws:
        `java.sql.SQLException`

    - #### detach

          public FirebirdBlob detach()
                              throws java.sql.SQLException

      Description copied from interface: `FirebirdBlob`
      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 a 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 `FirebirdBlob` that is not under result set control.
      Throws:
        `java.sql.SQLException` - if Blob cannot be detached.

    - #### getBytes

          public byte[] getBytes(long pos,
                                 int length)
                          throws java.sql.SQLException

      Specified by:
        `getBytes` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### getBinaryStream

          public java.io.InputStream getBinaryStream()
                                              throws java.sql.SQLException

      Specified by:
        `getBinaryStream` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### position

          public long position(byte[] pattern,
                               long start)
                        throws java.sql.SQLException

      Specified by:
        `position` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### position

          public long position(java.sql.Blob pattern,
                               long start)
                        throws java.sql.SQLException

      Specified by:
        `position` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### truncate

          public void truncate(long len)
                        throws java.sql.SQLException

      Specified by:
        `truncate` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### setBytes

          public int setBytes(long pos,
                              byte[] bytes)
                       throws java.sql.SQLException

      Specified by:
        `setBytes` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### setBytes

          public int setBytes(long pos,
                              byte[] bytes,
                              int offset,
                              int len)
                       throws java.sql.SQLException

      Specified by:
        `setBytes` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### setBinaryStream

          public java.io.OutputStream setBinaryStream(long pos)
                                               throws java.sql.SQLException

      Specified by:
        `setBinaryStream` in interface `java.sql.Blob`
      Throws:
        `java.sql.SQLException`

    - #### getBlobId

          public long getBlobId()
                         throws java.sql.SQLException

      Get the identifier for this `Blob`
      Returns:
        This `Blob`'s identifier
      Throws:
        `java.sql.SQLException` - if a database access error occurs

    - #### copyBytes

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

      Throws:
        `java.sql.SQLException`

    - #### copyStream

          public void copyStream(java.io.InputStream inputStream,
                                 long length)
                          throws java.sql.SQLException

      Copy the contents of an `InputStream` into this Blob.

      Calling with length `-1` is equivalent to calling `copyStream(InputStream)`, and will copy the whole stream.

      Parameters:
        `inputStream` - the stream from which data will be copied
        `length` - The maximum number of bytes to read from the InputStream, `-1` to read whole stream
      Throws:
        `java.sql.SQLException` - if a database access error occurs

    - #### copyStream

          public void copyStream(java.io.InputStream inputStream)
                          throws java.sql.SQLException

      Copy the contents of an `InputStream` into this Blob. Unlike the `copyStream(InputStream, long)` method, this one copies bytes until the EOF is reached.
      Parameters:
        `inputStream` - the stream from which data will be copied
      Throws:
        `java.sql.SQLException` - if a database access error occurs

    - #### copyCharacterStream

          public void copyCharacterStream(java.io.Reader reader,
                                          long length,
                                          Encoding encoding)
                                   throws java.sql.SQLException

      Copy data from a character stream into this Blob.

      Calling with length `-1` is equivalent to calling `copyCharacterStream(Reader, Encoding)`.

      Parameters:
        `reader` - the source of data to copy
        `length` - The maximum number of bytes to copy, or `-1` to read the whole stream
        `encoding` - The encoding used in the character stream
      Throws:
        `java.sql.SQLException`
      See Also:
        `copyCharacterStream(Reader, long)`

    - #### copyCharacterStream

          public void copyCharacterStream(java.io.Reader reader,
                                          long length)
                                   throws java.sql.SQLException

      Copy data from a character stream into this Blob. This method uses the encoding from the blob config (field character set for subtype TEXT, if known, otherwise connection character set).

      Calling with length `-1` is equivalent to calling `copyCharacterStream(Reader)`.

      Parameters:
        `reader` - the source of data to copy
        `length` - The maximum number of bytes to copy, or `-1` to read the whole stream
      Throws:
        `java.sql.SQLException`
      Since:
        5

    - #### copyCharacterStream

          public void copyCharacterStream(java.io.Reader reader,
                                          Encoding encoding)
                                   throws java.sql.SQLException

      Copy data from a character stream into this Blob. Unlike the `copyCharacterStream(Reader, long, Encoding)` method, this one copies bytes until the EOF is reached.
      Parameters:
        `reader` - the source of data to copy
        `encoding` - The encoding used in the character stream
      Throws:
        `java.sql.SQLException`
      See Also:
        `copyCharacterStream(Reader)`

    - #### copyCharacterStream

          public void copyCharacterStream(java.io.Reader reader)
                                   throws java.sql.SQLException

      Copy data from a character stream into this Blob. Unlike the `copyCharacterStream(Reader, long)` method, this one copies bytes until the EOF is reached. This method uses the encoding from the blob config (field character set for subtype TEXT, if known, otherwise connection character set).
      Parameters:
        `reader` - the source of data to copy
      Throws:
        `java.sql.SQLException`
      Since:
        5

    - #### transactionStateChanged

          public void transactionStateChanged(FbTransaction transaction,
                                              TransactionState newState,
                                              TransactionState previousState)

      Description copied from interface: `TransactionListener`
      Signals that the transaction state changed.
      Specified by:
        `transactionStateChanged` in interface `TransactionListener`
      Parameters:
        `transaction` - `FbTransaction` that changed state

    - #### createConfig

          @InternalApi
          public static FBBlob.Config createConfig(FieldDescriptor fieldDescriptor,
                                                                 DatabaseConnectionProperties connectionProperties)

      Creates a blob configuration from a field descriptor and connection properties.
      Parameters:
        `fieldDescriptor` - field descriptor
        `connectionProperties` - connection properties
      Returns:
        field based blob configuration
      Since:
        5

    - #### createConfig

          @InternalApi
          public static FBBlob.Config createConfig(int subType,
                                                                 DatabaseConnectionProperties connectionProperties,
                                                                 DatatypeCoder datatypeCoder)

      Creates a blob configuration from a subtype and connection properties and datatype coder.
      Parameters:
        `subType` - blob subtype (e.g. `ISCConstants.BLOB_SUB_TYPE_BINARY` or `ISCConstants.BLOB_SUB_TYPE_TEXT`)
        `connectionProperties` - connection properties
        `datatypeCoder` - data type coder for the connection character set
      Returns:
        field based blob configuration
      Since:
        5

    - #### createConfig

          @InternalApi
          public static FBBlob.Config createConfig(int subType,
                                                                 boolean useStreamBlob,
                                                                 int blobBufferSize,
                                                                 DatatypeCoder datatypeCoder)

      Create a blob configuration.
      Parameters:
        `subType` - blob subtype (e.g. `ISCConstants.BLOB_SUB_TYPE_BINARY` or `ISCConstants.BLOB_SUB_TYPE_TEXT`)
        `useStreamBlob` - `true` use stream blob, `false` use segmented blob
        `blobBufferSize` - blob buffer size
        `datatypeCoder` - data type coder for the connection character set
      Returns:
        generic blob configuration
      Since:
        5

Copyright © 2001-2025 Jaybird (Firebird JDBC) team. All rights reserved.