Top Description Fields Constructors Methods
org.apache.derby.impl.jdbc

pack-priv Class UpdatableBlobStream

extends InputStream
Class Inheritance
Imports
java.io.IOException, .InputStream, java.sql.SQLException, org.apache.derby.iapi.services.io.InputStreamUtil

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

Modifier and TypeField and Description
private final EmbedBlob
private boolean
materialized

Flag to check if it is using stream from LOBStreamControl or from DVD.

private final long
maxPos

Position in Blob where to stop reading unless EOF is reached first.

private long
private InputStream

Constructor Summary

AccessConstructor and Description
pack-priv
UpdatableBlobStream(EmbedBlob
EmbedBlob this stream is associated with.
blob
,
InputStream
InputStream this class is going to use internally.
is
)

Constructs UpdatableBlobStream using the the InputStream receives as the parameter.

pack-priv
UpdatableBlobStream(EmbedBlob
EmbedBlob this stream is associated with.
blob
,
InputStream
InputStream this class is going to use internally.
is
,
long
initial position
pos
,
long
The length to which the underlying InputStream has to be restricted.
len
)

Construct an UpdatableBlobStream using the InputStream received as parameter.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the next byte of data, or -1 if the end of the stream is reached.
read
()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int

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.
read
(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

public int

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.
read
(byte[]
the buffer into which the data is read.
b
)

Overrides java.io.InputStream.read.

Reads some number of bytes from the input stream and stores them into the buffer array b.

public long

Returns:

the actual number of bytes skipped.
skip
(long
the number of bytes to be skipped.
n
)

Overrides java.io.InputStream.skip.

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.

Inherited from java.io.InputStream:
availableclosemarkmarkSupportednullInputStreamreadAllBytesreadNBytesreadNBytesresetskipNBytestransferTo

Field Detail

blobback to summary
private final EmbedBlob blob
materializedback to summary
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.

maxPosback to summary
private final long maxPos

Position in Blob where to stop reading unless EOF is reached first.

posback to summary
private long pos
streamback to summary
private InputStream stream

Constructor Detail

UpdatableBlobStreamback to summary
pack-priv 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

EmbedBlob this stream is associated with.

is:InputStream

InputStream this class is going to use internally.

Exceptions
IOException:
if an I/O error occurs
UpdatableBlobStreamback to summary
pack-priv 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

EmbedBlob this stream is associated with.

is:InputStream

InputStream this class is going to use internally.

pos:long

initial position

len:long

The length to which the underlying InputStream has to be restricted.

Method Detail

readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

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.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Exceptions
IOException:
if an I/O error occurs.
See Also
InputStream#read
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

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 .

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

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.

Exceptions
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
java.io.InputStream#read(byte[], int, int)
readback to summary
public int read(byte[] b) throws IOException

Overrides java.io.InputStream.read.

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 .

Parameters
b:byte[]

the buffer into which the data is read.

Returns:int

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.

Exceptions
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
java.io.InputStream#read(byte[])
skipback to summary
public long skip(long n) throws IOException

Overrides java.io.InputStream.skip.

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 .

Parameters
n:long

the number of bytes to be skipped.

Returns:long

the actual number of bytes skipped.

Exceptions
IOException:
if the stream does not support seek, or if some other I/O error occurs.
See Also
java.io.InputStream#skip(long)
updateIfRequiredback to summary
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.