Class AutoPositioningStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.derby.impl.jdbc.BinaryToRawStream
org.apache.derby.impl.jdbc.AutoPositioningStream
- All Implemented Interfaces:
Closeable, AutoCloseable
This Stream is a wrapper for PositionedStoreStream to set the position
correctly before performing any operation on it.
All the read and skip methods ensure that the PositionedStoreStream
is set to right position before actually performing these operations.
PositionedStoreStream is accessed within synchronized block to ensure
exclusive access to it.
This class must be constructed while synchronizing on
ConnectionChild.getConnectionSynchronization
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConnectionChildConnectionChild to get synchronizion objectprivate longprivate final PositionedStoreStreamFields inherited from class FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionAutoPositioningStream(ConnectionChild conChild, InputStream in, Object parent) Constructs AutoPositioningStream object. -
Method Summary
Modifier and TypeMethodDescriptionintread()Reads a single byte from the underlying stream.intread(byte[] b) Reads a number of bytes from the underlying stream and stores them in the specified byte array.intread(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.private voidChecks if positionedStream's position was changed since last used, sets the position to right position if its changed.longskip(long n) Skips up to the specified number of bytes from the underlying stream.Methods inherited from class BinaryToRawStream
getLengthMethods inherited from class FilterInputStream
available, close, mark, markSupported, resetMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
conChild
ConnectionChild to get synchronizion object -
pos
private long pos -
positionedStream
-
-
Constructor Details
-
AutoPositioningStream
AutoPositioningStream(ConnectionChild conChild, InputStream in, Object parent) throws IOException Constructs AutoPositioningStream object. This constructor must be called from block synchronized on conChild.getConnectionSynchronization.- Parameters:
conChild- ConnectionChild to get synchronization object before accessing PositionedStoreStreamin- InputStreamparent- Parent of the stream to prevent it from being gc.- Throws:
IOException- if an I/O error occurs
-
-
Method Details
-
read
Reads a single byte from the underlying stream.- Overrides:
readin classFilterInputStream- Returns:
- The next byte of data, or -1 if the end of the stream is reached.
- Throws:
IOException- if an I/O error occurs
-
read
Reads a number of bytes from the underlying stream and stores them in the specified byte array at the specified offset.- Overrides:
readin classFilterInputStream- Returns:
- The actual number of bytes read, or -1 if the end of the stream is reached.
- Throws:
IOException- if an I/O error occurs
-
skip
Skips up to the specified number of bytes from the underlying stream.- Overrides:
skipin classFilterInputStream- Returns:
- The actual number of bytes skipped.
- Throws:
IOException- if an I/O error occurs
-
read
Reads a number of bytes from the underlying stream and stores them in the specified byte array.- Overrides:
readin classFilterInputStream- Returns:
- The actual number of bytes read, or -1 if the end of the stream is reached.
- Throws:
IOException- if an I/O error occurs
-
setPosition
Checks if positionedStream's position was changed since last used, sets the position to right position if its changed.- Throws:
IOException
-