java.lang.Object
java.io.Reader
net.i2p.sam.UTF8Reader
- All Implemented Interfaces:
Closeable, AutoCloseable, Readable
An unbuffered version of InputStreamReader.
Does not read any extra characters, as long as input is well-formed. This permits the partial reading of an InputStream as UTF-8 and then passing the remainder of the input stream elsewhere. This isn't the most robust for malformed input, so it may not be appropriate for e.g. HTTP headers.
Not thread-safe, obviously.
May be moved to net.i2p.util if anybody else needs it.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ByteBufferBytes buffered while decoding, initialized lazily when needed.private CharBufferCharacters decoded ahead of the reader, initialized lazily.private CharsetDecoderThe UTF-8 decoder, initialized lazily.private final InputStreamThe bytes being decoded.private static final intCharacter substituted for an undecodable byte.Constructor Summary
ConstructorsMethod Summary
All MethodsMethods inherited from class Reader
mark, markSupported, nullReader, of, read, readAllAsString, readAllLines, ready, reset, skip, transferTo
Field Details
_in
The bytes being decoded._bb
Bytes buffered while decoding, initialized lazily when needed._cb
Characters decoded ahead of the reader, initialized lazily._dc
The UTF-8 decoder, initialized lazily.REPLACEMENT
private static final int REPLACEMENTCharacter substituted for an undecodable byte.- See Also:
Constructor Details
UTF8Reader
Creates a reader that decodes the stream as UTF-8.- Parameters:
in- UTF-8
Method Details
read
Read one decoded character.- Overrides:
readin classReader- Returns:
- replacement character on decoding error
- Throws:
IOException
read
- Overrides:
readin classReader- Throws:
IOException
read
- Specified by:
readin classReader- Throws:
IOException
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException