Class Utf8ByteBufferReader
- java.lang.Object
-
- java.io.Reader
-
- javolution37.javolution.io.Utf8ByteBufferReader
-
- All Implemented Interfaces:
- java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable, Reusable
public final class Utf8ByteBufferReader extends java.io.Reader implements Reusable
This class represents a UTF-8
java.nio.ByteBufferreader.This reader can be used for efficient decoding of native byte buffers (e.g.
MappedByteBuffer), high-performance messaging (no intermediate buffer), etc.This reader supports surrogate
charpairs (representing characters in the range [U+10000 .. U+10FFFF]). It can also be used to read characters unicodes (31 bits) directly (ref.read()).Each invocation of one of the
read()methods may cause one or more bytes to be read from the underlying byte buffer. The end of stream is reached when the byte buffer position and limit coincide.- See Also:
Utf8ByteBufferWriter
-
-
Constructor Summary
Constructors Constructor and Description Utf8ByteBufferReader()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclose()Closes andresetsthis reader for reuse.intread()Reads a single character.voidread(java.lang.Appendable dest)Reads characters into the specified appendable.intread(char[] cbuf, int off, int len)Reads characters into a portion of an array.booleanready()Indicates if this stream is ready to be read.voidreset()Resets the internal state of this object to its default values.Utf8ByteBufferReadersetByteBuffer(java.nio.ByteBuffer byteBuffer)Sets theByteBufferto use for reading available bytes from current buffer position.
-
-
-
Method Detail
-
setByteBuffer
public Utf8ByteBufferReader setByteBuffer(java.nio.ByteBuffer byteBuffer)
Sets theByteBufferto use for reading available bytes from current buffer position.
-
ready
public boolean ready() throws java.io.IOExceptionIndicates if this stream is ready to be read.- Overrides:
readyin classjava.io.Reader- Returns:
trueif the byte buffer has remaining bytes to read;falseotherwise.- Throws:
java.io.IOException- if an I/O error occurs.
-
close
public void close() throws java.io.IOExceptionCloses andresetsthis reader for reuse.- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException- if an I/O error occurs.
-
read
public int read() throws java.io.IOExceptionReads a single character. This method does not block,-1is returned if the buffer's limit has been reached.- Overrides:
readin classjava.io.Reader- Returns:
- the 31-bits Unicode of the character read, or -1 if there is no more remaining bytes to be read.
- Throws:
java.io.IOException- if an I/O error occurs (e.g. incomplete character sequence being read).
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOExceptionReads characters into a portion of an array. This method does not block.Note: Characters between U+10000 and U+10FFFF are represented by surrogate pairs (two
char).- Specified by:
readin classjava.io.Reader- Parameters:
cbuf- the destination buffer.off- the offset at which to start storing characters.len- the maximum number of characters to read- Returns:
- the number of characters read, or 0 if there is no more remaining bytes to be read.
- Throws:
java.io.IOException- if an I/O error occurs.
-
read
public void read(java.lang.Appendable dest) throws java.io.IOExceptionReads characters into the specified appendable. This method does not block.Note: Characters between U+10000 and U+10FFFF are represented by surrogate pairs (two
char).- Parameters:
dest- the destination buffer.- Throws:
java.io.IOException- if an I/O error occurs.
-
-
DMelt 3.0 © DataMelt by jWork.ORG