Package org.apache.derby.impl.jdbc
Class UpdatableBlobStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.derby.impl.jdbc.UpdatableBlobStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
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
Fields Modifier and Type Field Description 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
Constructors Constructor Description 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 anUpdatableBlobStream
using theInputStream
received as parameter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 arrayb
.int
read(byte[] b, int off, int len)
Reads up tolen
bytes of data from the input stream into an array of bytes.long
skip(long n)
Skips over and discardsn
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.
-
-
-
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 the0
.- 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 anUpdatableBlobStream
using theInputStream
received as parameter. The initial position in the stream is set topos
and the stream is restricted to a length oflen
.- Parameters:
blob
- EmbedBlob this stream is associated with.is
- InputStream this class is going to use internally.pos
- initial positionlen
- The length to which the underlyingInputStream
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 anint
in the range0
to255
. 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 classjava.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 tolen
bytes of data from the input stream into an array of bytes. An attempt is made to read as many aslen
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 classjava.io.InputStream
- Parameters:
b
- the buffer into which the data is read.off
- the start offset in arrayb
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
- Ifb
isnull
.java.lang.IndexOutOfBoundsException
- Ifoff
is negative,len
is negative, orlen
is greater thanb.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 arrayb
. 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 classjava.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
- ifb
isnull
.- See Also:
InputStream.read(byte[])
-
skip
public long skip(long n) throws java.io.IOException
Skips over and discardsn
bytes of data from this input stream. Theskip
method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly0
. This may result from any of a number of conditions; reaching end of file beforen
bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. Ifn
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 classjava.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)
-
-