org.apache.derby.impl.jdbc
Class UpdatableBlobStream

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

 class UpdatableBlobStream
extends java.io.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 Summary
private  EmbedBlob blob
           
private  boolean materialized
          Flag to check if it is using stream from LOBStreamControl or from DVD.
private  long maxPos
          Position in Blob where to stop reading unless EOF is reached first.
private  long pos
           
private  java.io.InputStream stream
           
 
Constructor Summary
UpdatableBlobStream(EmbedBlob blob, java.io.InputStream is)
          Constructs UpdatableBlobStream using the the InputStream receives as the parameter.
UpdatableBlobStream(EmbedBlob blob, java.io.InputStream is, long pos, long len)
          Construct an UpdatableBlobStream using the InputStream received as parameter.
 
Method Summary
 int read()
          Reads the next byte of data from the input stream.
 int read(byte[] b)
          Reads some number of bytes from the input stream and stores them into the buffer array b.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from the input stream into an array of bytes.
 long skip(long n)
          Skips over and discards n bytes of data from this input stream.
private  void updateIfRequired()
          Checks if this object is using materialized blob if not it checks if the blob was materialized since this stream was last access.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 java.io.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 Detail

UpdatableBlobStream

UpdatableBlobStream(EmbedBlob blob,
                    java.io.InputStream is)
              throws java.io.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:
java.io.IOException - if an I/O error occurs

UpdatableBlobStream

UpdatableBlobStream(EmbedBlob blob,
                    java.io.InputStream is,
                    long pos,
                    long len)
              throws java.io.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:
java.io.IOException
Method Detail

updateIfRequired

private void updateIfRequired()
                       throws java.io.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:
java.io.IOException

read

public int read()
         throws java.io.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 java.io.InputStream
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
InputStream.read()

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.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 java.io.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:
java.io.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.
java.lang.NullPointerException - If b is null.
java.lang.IndexOutOfBoundsException - If off is negative, len is negative, or len is greater than b.length - off
See Also:
InputStream.read(byte[],int,int)

read

public int read(byte[] b)
         throws java.io.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 java.io.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:
java.io.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.
java.lang.NullPointerException - if b is null.
See Also:
InputStream.read(byte[])

skip

public long skip(long n)
          throws java.io.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 java.io.InputStream
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
java.io.IOException - if the stream does not support seek, or if some other I/O error occurs.
See Also:
InputStream.skip(long)

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.