Class UpdatableBlobStream

java.lang.Object
java.io.InputStream
org.apache.derby.impl.jdbc.UpdatableBlobStream
All Implemented Interfaces:
Closeable, AutoCloseable

class UpdatableBlobStream extends InputStream
Updatable blob stream is a wrapper stream over dvd stream and LOBInputStream. It detects if blob data has moved from dvd to clob control. If this happens, it will update itself to point to LOBInputStream and reflect changes made to the Blob after the current position of the stream.
  • Field Details

    • materialized

      private boolean materialized
      Flag to check if it is using stream from LOBStreamControl or from DVD. true means data is read from LOBStreamControl, false means data is read from the DVD.
    • stream

      private InputStream stream
    • pos

      private long pos
    • blob

      private final EmbedBlob blob
    • maxPos

      private final long maxPos
      Position in Blob where to stop reading unless EOF is reached first.
  • Constructor Details

    • UpdatableBlobStream

      UpdatableBlobStream(EmbedBlob blob, InputStream is) throws IOException
      Constructs UpdatableBlobStream using the the InputStream receives as the parameter. The initial position is set to the 0.
      Parameters:
      blob - EmbedBlob this stream is associated with.
      is - InputStream this class is going to use internally.
      Throws:
      IOException - if an I/O error occurs
    • UpdatableBlobStream

      UpdatableBlobStream(EmbedBlob blob, InputStream is, long pos, long len) throws IOException
      Construct an UpdatableBlobStream using the InputStream received as parameter. The initial position in the stream is set to pos and the stream is restricted to a length of len.
      Parameters:
      blob - EmbedBlob this stream is associated with.
      is - InputStream this class is going to use internally.
      pos - initial position
      len - The length to which the underlying InputStream has to be restricted.
      Throws:
      IOException
  • Method Details

    • updateIfRequired

      private void updateIfRequired() throws IOException
      Checks if this object is using materialized blob if not it checks if the blob was materialized since this stream was last access. If the blob was materialized (due to one of the set methods) it gets the stream again and sets the position to current read position.
      Throws:
      IOException
    • read

      public int read() throws IOException
      Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

      A subclass must provide an implementation of this method.

      Note that this stream will reflect changes made to the underlying Blob at positions equal to or larger then the current position.

      Specified by:
      read in class InputStream
      Returns:
      the next byte of data, or -1 if the end of the stream is reached.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

      Note that this stream will reflect changes made to the underlying Blob at positions equal to or larger then the current position .

      Overrides:
      read in class InputStream
      Parameters:
      b - the buffer into which the data is read.
      off - the start offset in array b at which the data is written.
      len - the maximum number of bytes to read.
      Returns:
      the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
      Throws:
      IOException - If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
      NullPointerException - If b is null.
      IndexOutOfBoundsException - If off is negative, len is negative, or len is greater than b.length - off
      See Also:
    • read

      public int read(byte[] b) throws IOException
      Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

      Note that this stream will reflect changes made to the underlying Blob at positions equal to or larger then the current position .

      Overrides:
      read in class InputStream
      Parameters:
      b - the buffer into which the data is read.
      Returns:
      the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
      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.
      NullPointerException - if b is null.
      See Also:
    • skip

      public long skip(long n) throws IOException
      Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped.

      Note that this stream will reflect changes made to the underlying Blob at positions equal to or larger then the current position .

      Overrides:
      skip in class InputStream
      Parameters:
      n - the number of bytes to be skipped.
      Returns:
      the actual number of bytes skipped.
      Throws:
      IOException - if the stream does not support seek, or if some other I/O error occurs.
      See Also: