Interface FirebirdBlob.BlobInputStream

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
FBBlobInputStream
Enclosing interface:
FirebirdBlob

public static interface FirebirdBlob.BlobInputStream extends AutoCloseable
Blob input stream. This interface defines methods to access contents of the Blob field. Some method signatures are copied from the InputStream only because it is abstract class and not interface that we can extend.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Seek based on the absolute beginning of the stream
    static final int
    Seek relative to the tail end of the stream
    static final int
    Seek relative to the current position in the stream
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Get number of available bytes that can be read without blocking.
    void
    Close this stream.
    Get instance of FirebirdBlob to which this stream belongs to.
    long
    Get Blob length.
    int
    Read a single byte from the stream.
    int
    read(byte[] buffer, int offset, int length)
    Read some bytes from the stream into buffer.
    void
    readFully(byte[] buffer)
    Read buffer.length bytes from the buffer.
    void
    readFully(byte[] buffer, int offset, int length)
    Read length from the stream into the specified buffer.
    int
    readNBytes(byte[] b, int off, int len)
     
    byte[]
    readNBytes(int len)
     
    void
    seek(int position)
    Move current position in the Blob stream.
    void
    seek(int position, int seekMode)
    Move current position in the Blob stream.
  • Field Details

    • SEEK_MODE_ABSOLUTE

      static final int SEEK_MODE_ABSOLUTE
      Seek based on the absolute beginning of the stream
      See Also:
    • SEEK_MODE_RELATIVE

      static final int SEEK_MODE_RELATIVE
      Seek relative to the current position in the stream
      See Also:
    • SEEK_MODE_FROM_TAIL

      static final int SEEK_MODE_FROM_TAIL
      Seek relative to the tail end of the stream
      See Also:
  • Method Details

    • getBlob

      FirebirdBlob getBlob()
      Get instance of FirebirdBlob to which this stream belongs to.

      Note, code

       FirebirdBlob.BlobInputStream otherStream = (FirebirdBlob.BlobInputStream)
           inputStream.getBlob().getBinaryStream();
       
      will return new stream object.
      Returns:
      instance of FirebirdBlob.
    • available

      int available() throws IOException
      Get number of available bytes that can be read without blocking. This method will return number of bytes of the last read blob segment in the blob buffer.
      Returns:
      number of bytes available without blocking or -1 if end of stream is reached.
      Throws:
      IOException - if I/O error occurred.
    • close

      void close() throws IOException
      Close this stream.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - if I/O error occurs.
    • length

      long length() throws IOException
      Get Blob length. This is a shortcut for inputStream.getBlob().length() call, and is more resource friendly, because no new Blob handle is created.
      Returns:
      length of the blob
      Throws:
      IOException - if I/O error occurs
    • read

      int read() throws IOException
      Read a single byte from the stream.
      Returns:
      next byte read from the stream or -1 if end of stream was reached
      Throws:
      IOException - if I/O error occurs
      See Also:
    • read

      int read(byte[] buffer, int offset, int length) throws IOException
      Read some bytes from the stream into buffer.

      The implementation may read less bytes than requested. Implementations may perform multiple roundtrips to the server to fill buffer up to the requested length.

      Parameters:
      buffer - buffer into which data should be read
      offset - offset in the buffer where to start
      length - number of bytes to read
      Returns:
      number of bytes that were actually read, returns 0 if len == 0, -1 if end-of-blob was reached without reading any bytes
      Throws:
      IOException - if I/O error occurs
      See Also:
    • readFully

      void readFully(byte[] buffer, int offset, int length) throws IOException
      Read length from the stream into the specified buffer.

      This method will throw an EOFException if end-of-blob was reached before reading length bytes.

      Parameters:
      buffer - buffer where data should be read
      offset - offset in the buffer where to start
      length - number of bytes to read
      Throws:
      EOFException - if stream end was reached when reading data.
      IOException - if I/O error occurs.
    • readFully

      void readFully(byte[] buffer) throws IOException
      Read buffer.length bytes from the buffer. This is a shortcut method for readFully(buffer, 0, buffer.length) call.
      Parameters:
      buffer - buffer where data should be read
      Throws:
      IOException - if I/O error occurs
    • readNBytes

      int readNBytes(byte[] b, int off, int len) throws IOException
      Throws:
      IOException
      See Also:
    • readNBytes

      byte[] readNBytes(int len) throws IOException
      Throws:
      IOException
      See Also:
    • seek

      void seek(int position) throws IOException
      Move current position in the Blob stream. This is a shortcut method to seek(int, int) passing SEEK_MODE_ABSOLUTE as seek mode.
      Parameters:
      position - absolute position to seek, starting position is 0 (note, in Blob.getBytes(long, int) starting position is 1).
      Throws:
      IOException - if I/O error occurs.
    • seek

      void seek(int position, int seekMode) throws IOException
      Move current position in the Blob stream. Depending on the specified seek mode, position can be either positive or negative.
      Parameters:
      position - position in the stream, starting position is 0 (note, in Blob.getBytes(long, int) starting position is 1)
      seekMode - mode of seek operation, one of SEEK_MODE_ABSOLUTE, SEEK_MODE_RELATIVE or SEEK_MODE_FROM_TAIL
      Throws:
      IOException - if I/O error occurs