Note that we often operate on a special Derby stream.
A Derby stream is possibly different from a "normal" stream in two ways;
an encoded length is inserted at the head of the stream, and if the encoded
length is 0 a Derby-specific end of stream marker is appended
to the data.
If the underlying stream is capable of repositioning itself on request, this class supports multiple readers on the same source stream in such a way that the various readers do not interfere with each other (except for serializing access). Each reader instance will have its own pointer into the stream, and request that the stream repositions itself before calling read/skip on the stream.
PositionedStoreStream
| Modifier and Type | Field and Description |
|---|---|
| private final char[] | buffer
Internal character buffer storing characters read from the stream. |
| private int | charactersInBuffer
The number of characters in the internal buffer. |
| private final CharacterStreamDescriptor | csd
Descriptor containing information about the stream. |
| private InputStream | in
The underlying data stream. |
| private static final int | MAXIMUM_BUFFER_SIZE
Maximum size in number of chars for the internal character buffer. |
| private boolean | noMoreReads
Tells if this reader has been closed. |
| private ConnectionChild | parent
A reference to the parent object of the stream. |
| private final PositionedStream | positionedIn
Stream that can reposition itself on request (may be |
| private long | rawStreamPos
Store the last visited position in the store stream, if it is capable of
repositioning itself ( |
| private static final String | |
| private long | readerCharCount
Number of characters read from the stream. |
| private int | readPositionInBuffer
The position of the next character to read in the internal buffer. |
| private long | utfCount
Number of bytes read from the stream, including any header bytes. |
| Access | Constructor and Description |
|---|---|
| public | UTF8Reader(CharacterStreamDescriptor
a description of and reference to the source stream csd, ConnectionChild the parent object / connection child conChild, Object synchronization object used when accessing the underlying
data stream sync)Constructs a reader on top of the source UTF-8 encoded stream. |
| Modifier and Type | Method and Description |
|---|---|
| private final int | Returns: An (sub)optimal buffer size.stream descriptor csd)Calculates an optimized buffer size. |
| public void | close()
Implements abstract java. Implements java. Close the reader, disallowing further reads. |
| private void | |
| private boolean | Returns: true if the end of the stream is reached,
false if there is apparently more data to be read.Fills the internal character buffer by decoding bytes from the stream. |
| private final void | |
| public int | Returns: A character or-1 if end of stream has been reached.Overrides java. Reads a single character from the stream. |
| public int | Returns: The number of characters read, or-1 if the end of
the stream has been reached.Destination buffer cbuf, int Offset at which to start storing characters off, int Maximum number of characters to read len)Implements abstract java. Reads characters into an array. |
| pack-priv int | Returns: The number of characters read, or-1 if the end of
the stream is reached.the buffer to read into abuf, int the offset into the destination buffer off, int maximum number of characters to read len)Reads characters into an array as ASCII characters. |
| public int | Returns: The number of characters read, or-1 if the end of
the stream is reached.the destination buffer sb, int maximum number of characters to read len)Reads characters from the stream. |
| pack-priv void | reposition(long
1-based requested character position requestedCharPos)Repositions the stream so that the next character read will be the character at the requested position. |
| private void | |
| public long | Returns: The number of characters actually skipped.the numbers of characters to skip len)Overrides java. Skips characters. |
| private IOException | utfFormatException(String s)
Convenience method generating an |
| buffer | back to summary |
|---|---|
| private final char[] buffer Internal character buffer storing characters read from the stream. | |
| charactersInBuffer | back to summary |
|---|---|
| private int charactersInBuffer The number of characters in the internal buffer. | |
| csd | back to summary |
|---|---|
| private final CharacterStreamDescriptor csd Descriptor containing information about the stream. Except for the current positions, the information in this object is considered permanent and valid for the life-time of the stream. | |
| in | back to summary |
|---|---|
| private InputStream in The underlying data stream. | |
| MAXIMUM_BUFFER_SIZE | back to summary |
|---|---|
| private static final int MAXIMUM_BUFFER_SIZE Maximum size in number of chars for the internal character buffer. | |
| noMoreReads | back to summary |
|---|---|
| private boolean noMoreReads Tells if this reader has been closed. | |
| parent | back to summary |
|---|---|
| private ConnectionChild parent A reference to the parent object of the stream. The reference is kept so that the parent object can't get garbage collected until we are done with the stream. | |
| positionedIn | back to summary |
|---|---|
| private final PositionedStream positionedIn Stream that can reposition itself on request (may be | |
| rawStreamPos | back to summary |
|---|---|
| private long rawStreamPos Store the last visited position in the store stream, if it is capable of
repositioning itself ( | |
| READER_CLOSED | back to summary |
|---|---|
| private static final String READER_CLOSED | |
| readerCharCount | back to summary |
|---|---|
| private long readerCharCount Number of characters read from the stream. | |
| readPositionInBuffer | back to summary |
|---|---|
| private int readPositionInBuffer The position of the next character to read in the internal buffer. | |
| utfCount | back to summary |
|---|---|
| private long utfCount Number of bytes read from the stream, including any header bytes. | |
| UTF8Reader | back to summary |
|---|---|
| public UTF8Reader(CharacterStreamDescriptor csd, ConnectionChild conChild, Object sync) throws IOException Constructs a reader on top of the source UTF-8 encoded stream.
| |
| calculateBufferSize | back to summary |
|---|---|
| private final int calculateBufferSize(CharacterStreamDescriptor csd) Calculates an optimized buffer size. The maximum size allowed is returned if the specified values don't give enough information to say a smaller buffer size is preferable.
| |
| close | back to summary |
|---|---|
| public void close() Implements abstract java. Implements java. Close the reader, disallowing further reads. | |
| closeIn | back to summary |
|---|---|
| private void closeIn() Close the underlying stream if it is open. | |
| fillBuffer | back to summary |
|---|---|
| private boolean fillBuffer() throws IOException Fills the internal character buffer by decoding bytes from the stream.
| |
| persistentSkip | back to summary |
|---|---|
| private final void persistentSkip(long toSkip) throws IOException Skips the requested number of characters.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Overrides java. Reads a single character from the stream.
| |
| read | back to summary |
|---|---|
| public int read(char[] cbuf, int off, int len) throws IOException Implements abstract java. Reads characters into an array.
| |
| readAsciiInto | back to summary |
|---|---|
| pack-priv int readAsciiInto(byte[] abuf, int off, int len) throws IOException Reads characters into an array as ASCII characters.
Due to internal buffering a smaller number of characters than what is
requested might be returned. To ensure that the request is fulfilled,
call this method in a loop until the requested number of characters is
read or Characters outside the ASCII range are replaced with an out of range marker.
| |
| readInto | back to summary |
|---|---|
| public int readInto(StringBuffer sb, int len) throws IOException Reads characters from the stream.
Due to internal buffering a smaller number of characters than what is
requested might be returned. To ensure that the request is fulfilled,
call this method in a loop until the requested number of characters is
read or
| |
| reposition | back to summary |
|---|---|
| pack-priv void reposition(long requestedCharPos) throws IOException, StandardException Repositions the stream so that the next character read will be the character at the requested position. There are three types of repositioning, ordered after increasing cost:
| |
| resetUTF8Reader | back to summary |
|---|---|
| private void resetUTF8Reader() throws IOException, StandardException Resets the reader. This method is used internally to achieve better performance.
| |
| skip | back to summary |
|---|---|
| public long skip(long len) throws IOException Overrides java. Skips characters.
| |
| utfFormatException | back to summary |
|---|---|
| private IOException utfFormatException(String s) Convenience method generating an | |