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.InputStreamUpdatable 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 EmbedBlobblobprivate booleanmaterializedFlag to check if it is using stream from LOBStreamControl or from DVD.private longmaxPosPosition in Blob where to stop reading unless EOF is reached first.private longposprivate java.io.InputStreamstream
-
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 anUpdatableBlobStreamusing theInputStreamreceived as parameter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intread()Reads the next byte of data from the input stream.intread(byte[] b)Reads some number of bytes from the input stream and stores them into the buffer arrayb.intread(byte[] b, int off, int len)Reads up tolenbytes of data from the input stream into an array of bytes.longskip(long n)Skips over and discardsnbytes of data from this input stream.private voidupdateIfRequired()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.truemeans data is read from LOBStreamControl,falsemeans 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 anUpdatableBlobStreamusing theInputStreamreceived as parameter. The initial position in the stream is set toposand 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 underlyingInputStreamhas to be restricted.- Throws:
java.io.IOException
-
-
Method Detail
-
updateIfRequired
private void updateIfRequired() throws java.io.IOExceptionChecks 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.IOExceptionReads the next byte of data from the input stream. The value byte is returned as anintin the range0to255. If no byte is available because the end of the stream has been reached, the value-1is 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:
readin classjava.io.InputStream- Returns:
- the next byte of data, or
-1if 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.IOExceptionReads up tolenbytes of data from the input stream into an array of bytes. An attempt is made to read as many aslenbytes, 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:
readin classjava.io.InputStream- Parameters:
b- the buffer into which the data is read.off- the start offset in arraybat which the data is written.len- the maximum number of bytes to read.- Returns:
- the total number of bytes read into the buffer, or
-1if 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- Ifbisnull.java.lang.IndexOutOfBoundsException- Ifoffis negative,lenis negative, orlenis greater thanb.length - off- See Also:
InputStream.read(byte[],int,int)
-
read
public int read(byte[] b) throws java.io.IOExceptionReads 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:
readin classjava.io.InputStream- Parameters:
b- the buffer into which the data is read.- Returns:
- the total number of bytes read into the buffer, or
-1is 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- ifbisnull.- See Also:
InputStream.read(byte[])
-
skip
public long skip(long n) throws java.io.IOExceptionSkips over and discardsnbytes of data from this input stream. Theskipmethod 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 beforenbytes have been skipped is only one possibility. The actual number of bytes skipped is returned. Ifnis 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:
skipin 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)
-
-