Class DbInputStream

All Implemented Interfaces:
Closeable, AutoCloseable

public class DbInputStream extends AutoCloseInputStream
This class represents an input stream backed by a database. The database objects are only acquired when reading from the stream, and stay open until the stream is closed, fully read, or garbage collected.

This class does not support mark/reset. It is always to be wrapped using a BufferedInputStream.

  • Method Details

    • read

      public int read() throws IOException
      Invokes the delegate's InputStream.read() method unless the stream is closed. When the stream is consumed, the database objects held by the instance are closed.
      Overrides:
      read in class ProxyInputStream
      Returns:
      the byte read or EOF if we reached the end of stream.
      Throws:
      IOException - if an I/O error occurs.
    • read

      public int read(byte[] b) throws IOException
      Invokes the delegate's InputStream.read(byte[]) method. When the stream is consumed, the database objects held by the instance are closed.
      Overrides:
      read in class ProxyInputStream
      Parameters:
      b - the buffer to read the bytes into.
      Returns:
      the number of bytes read or EOF if we reached the end of stream.
      Throws:
      IOException -
      • If the first byte cannot be read for any reason other than the end of the file,
      • if the input stream has been closed, or
      • if some other I/O error occurs.
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Invokes the delegate's InputStream.read(byte[], int, int) method. When the stream is consumed, the database objects held by the instance are closed.
      Overrides:
      read in class ProxyInputStream
      Parameters:
      b - the buffer to read the bytes into.
      off - The start offset.
      len - The number of bytes to read.
      Returns:
      the number of bytes read or EOF if we reached the end of stream.
      Throws:
      IOException -
      • If the first byte cannot be read for any reason other than the end of the file,
      • if the input stream has been closed, or
      • if some other I/O error occurs.
    • close

      public void close() throws IOException
      Closes the underlying input stream and replaces the reference to it with a ClosedInputStream instance.

      This method is automatically called by the read methods when the end of input has been reached.

      Note that it is safe to call this method any number of times. The original underlying input stream is closed and discarded only once when this method is first called.

      When the stream is consumed, the database objects held by the instance are closed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class AutoCloseInputStream
      Throws:
      IOException - if the underlying input stream cannot be closed
    • skip

      public long skip(long n) throws IOException
      Invokes the delegate's InputStream.skip(long) method.
      Overrides:
      skip in class ProxyInputStream
      Parameters:
      n - the number of bytes to skip.
      Returns:
      the actual number of bytes skipped.
      Throws:
      IOException - if the stream does not support seek, or if some other I/O error occurs.
    • available

      public int available() throws IOException
      Invokes the delegate's InputStream.available() method.
      Overrides:
      available in class ProxyInputStream
      Returns:
      the number of available bytes, 0 if the stream is closed.
      Throws:
      IOException - if an I/O error occurs.
    • mark

      public void mark(int readlimit)
      This method does nothing.
      Overrides:
      mark in class ProxyInputStream
      Parameters:
      readlimit - read ahead limit.
    • reset

      public void reset() throws IOException
      This method does nothing.
      Overrides:
      reset in class ProxyInputStream
      Throws:
      IOException - if this stream has not been marked or if the mark has been invalidated.
    • markSupported

      public boolean markSupported()
      Check whether mark and reset are supported.
      Overrides:
      markSupported in class ProxyInputStream
      Returns:
      false
      See Also: