|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.InputStream
org.apache.derby.impl.jdbc.PositionedStoreStream
public class PositionedStoreStream
A wrapper-stream able to reposition the underlying store stream.
Where a user expects the underlying stream to be at a given position,
reposition(long) must be called with the expected position first. A use
case for this scenario is the LOB objects, where you can request a stream and
at the same time (this does not mean concurrently) query the LOB about its
length or ask to get a part of the LOB returned. Such multiplexed operations
must result in consistent and valid data, and to achieve this the underlying
store stream must be able to reposition itself.
Synchronization: Access to instances of this class must be
externally synchronized on the connection synchronization object. There are
two reasons for this:
EmbedConnection.getConnectionSynchronization()| Field Summary | |
|---|---|
private long |
pos
Position of the underlying store stream. |
private java.io.InputStream |
stream
Underlying store stream serving bytes. |
| Constructor Summary | |
|---|---|
PositionedStoreStream(java.io.InputStream in)
Creates a positioned store stream on top of the specified resettable stream. |
|
| Method Summary | |
|---|---|
java.io.InputStream |
asInputStream()
Returns a reference to self as an InputStream. |
void |
closeStream()
Closes the resettable stream. |
long |
getPosition()
Returns the current position of the underlying store stream. |
void |
initStream()
Initialize the resettable stream for use. |
int |
read()
Reads a single byte from the underlying stream. |
int |
read(byte[] b)
Reads a number of bytes from the underlying stream and stores them in the specified byte array. |
int |
read(byte[] b,
int off,
int len)
Reads a number of bytes from the underlying stream and stores them in the specified byte array at the specified offset. |
void |
reposition(long requestedPos)
Repositions the underlying store stream to the requested position. |
void |
resetStream()
Resets the resettable stream. |
long |
skip(long toSkip)
Skips up to the specified number of bytes from the underlying stream. |
| 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 |
|---|
private final java.io.InputStream stream
private long pos
| Constructor Detail |
|---|
public PositionedStoreStream(java.io.InputStream in)
throws java.io.IOException,
StandardException
Upon creation, the underlying stream is initiated and reset to make sure the states of the streams are in sync with each other.
in - a Resetable-stream
java.io.IOException
StandardException| Method Detail |
|---|
public int read(byte[] b)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException - if an I/O error occurs
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException - if an I/O error occurs
public int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException - if an I/O error occurs
public long skip(long toSkip)
throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOException - if an I/O error occurs
public void resetStream()
throws java.io.IOException,
StandardException
resetStream in interface Resetablejava.io.IOException
StandardException - if resetting the stream in store failsResetable.resetStream()
public void initStream()
throws StandardException
initStream in interface ResetableStandardException - if initializing the store in stream failsResetable.initStream()public void closeStream()
closeStream in interface ResetableResetable.closeStream()
public void reposition(long requestedPos)
throws java.io.IOException,
StandardException
Repositioning is required because there can be several uses of the store stream, which changes the position of it. If a class is dependent on the underlying stream not changing its position, it must call reposition with the position it expects before using the stream again.
If the repositioning fails because the stream is exhausted, most likely
because of an invalid position specified by the user, the stream is
reset to position zero and the EOFException is rethrown.
reposition in interface PositionedStreamrequestedPos - requested byte position, first position is 0
java.io.EOFException - if the stream is exhausted before the requested
position is reached
java.io.IOException - if reading from the store stream fails
StandardException - if resetting the store in stream fails, or
some other exception happens in storegetPosition()public long getPosition()
getPosition in interface PositionedStreampublic java.io.InputStream asInputStream()
PositionedStreamInputStream.
This method is not allowed to return null.
asInputStream in interface PositionedStreamInputStream reference to self.
|
Built on Wed 2013-06-12 15:21:56+0000, from revision ??? | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||