Class UTF8Reader
- java.lang.Object
-
- java.io.Reader
-
- org.apache.derby.impl.jdbc.UTF8Reader
-
- All Implemented Interfaces:
- java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable
public final class UTF8Reader extends java.io.ReaderClass for reading characters from streams encoded in the modified UTF-8 format.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
0a 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.
- See Also:
PositionedStoreStream
-
-
Constructor Summary
Constructors Constructor and Description UTF8Reader(CharacterStreamDescriptor csd, org.apache.derby.impl.jdbc.ConnectionChild conChild, java.lang.Object sync)Constructs a reader on top of the source UTF-8 encoded stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclose()Close the reader, disallowing further reads.intread()Reads a single character from the stream.intread(char[] cbuf, int off, int len)Reads characters into an array.intreadInto(java.lang.StringBuffer sb, int len)Reads characters from the stream.longskip(long len)Skips characters.
-
-
-
Constructor Detail
-
UTF8Reader
public UTF8Reader(CharacterStreamDescriptor csd, org.apache.derby.impl.jdbc.ConnectionChild conChild, java.lang.Object sync) throws java.io.IOException
Constructs a reader on top of the source UTF-8 encoded stream.- Parameters:
csd- a description of and reference to the source streamconChild- the parent object / connection childsync- synchronization object used when accessing the underlying data stream- Throws:
java.io.IOException- if reading from the underlying stream fails
-
-
Method Detail
-
read
public int read() throws java.io.IOExceptionReads a single character from the stream.- Overrides:
readin classjava.io.Reader- Returns:
- A character or
-1if end of stream has been reached. - Throws:
java.io.IOException- if the stream has been closed, or an exception is raised while reading from the underlying stream
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOExceptionReads characters into an array.- Specified by:
readin classjava.io.Reader- Returns:
- The number of characters read, or
-1if the end of the stream has been reached. - Throws:
java.io.IOException
-
skip
public long skip(long len) throws java.io.IOExceptionSkips characters.- Overrides:
skipin classjava.io.Reader- Parameters:
len- the numbers of characters to skip- Returns:
- The number of characters actually skipped.
- Throws:
java.lang.IllegalArgumentException- if the number of characters to skip is negativejava.io.IOException- if accessing the underlying stream fails
-
close
public void close()
Close the reader, disallowing further reads.- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein classjava.io.Reader
-
readInto
public int readInto(java.lang.StringBuffer sb, int len) throws java.io.IOExceptionReads 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
-1is returned.- Parameters:
sb- the destination bufferlen- maximum number of characters to read- Returns:
- The number of characters read, or
-1if the end of the stream is reached. - Throws:
java.io.IOException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG