Class UTF8Reader
- java.lang.Object
-
- java.io.Reader
-
- com.fasterxml.jackson.dataformat.toml.UTF8Reader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public final class UTF8Reader extends java.io.ReaderOptimized Reader that reads UTF-8 encoded content from an input stream. Content may come either from a staticbyte[]buffer orInputStream.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean_autoCloseprivate int_byteCountTotal read byte count; used for error reporting purposesprivate int_charCountTotal read character count; used for error reporting purposesprivate byte[]_inputBufferprivate int_inputEndPointed to the end marker, that is, position one after the last valid available byte.private int_inputPtrPointer to the next available byte (if any), iff less thanmByteBufferEndprivate java.io.InputStream_inputSourceprivate com.fasterxml.jackson.core.io.IOContext_ioContextIO context to use for returning input buffer, iff buffer is to be recycled when input ends.private int_surrogateDecoded first character of a surrogate pair, if one needs to be bufferedprivate char[]_tmpBuffer
-
Constructor Summary
Constructors Modifier Constructor Description privateUTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, java.io.InputStream in, boolean autoClose, byte[] buf, int ptr, int end)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanModifyBuffer()Method that can be used to see if we can actually modify the underlying buffer.voidclose()static UTF8Readerconstruct(byte[] buf, int ptr, int len)static UTF8Readerconstruct(com.fasterxml.jackson.core.io.IOContext ctxt, java.io.InputStream in, boolean autoClose)private voidfreeBuffers()This method should be called along with (or instead of) normal close.private booleanloadMore(int available)intread()intread(char[] cbuf)intread(char[] cbuf, int start, int len)protected intreadBytes()protected intreadBytesAt(int offset)protected voidreportBounds(char[] cbuf, int start, int len)private voidreportInvalidInitial(int mask, int offset)private voidreportInvalidOther(int mask, int offset)protected voidreportStrangeStream()private voidreportUnexpectedEOF(int gotBytes, int needed)
-
-
-
Field Detail
-
_ioContext
private final com.fasterxml.jackson.core.io.IOContext _ioContext
IO context to use for returning input buffer, iff buffer is to be recycled when input ends.
-
_inputSource
private java.io.InputStream _inputSource
-
_autoClose
private final boolean _autoClose
-
_inputBuffer
private byte[] _inputBuffer
-
_inputPtr
private int _inputPtr
Pointer to the next available byte (if any), iff less thanmByteBufferEnd
-
_inputEnd
private int _inputEnd
Pointed to the end marker, that is, position one after the last valid available byte.
-
_surrogate
private int _surrogate
Decoded first character of a surrogate pair, if one needs to be buffered
-
_charCount
private int _charCount
Total read character count; used for error reporting purposes
-
_byteCount
private int _byteCount
Total read byte count; used for error reporting purposes
-
_tmpBuffer
private char[] _tmpBuffer
-
-
Method Detail
-
construct
public static UTF8Reader construct(com.fasterxml.jackson.core.io.IOContext ctxt, java.io.InputStream in, boolean autoClose)
-
construct
public static UTF8Reader construct(byte[] buf, int ptr, int len)
-
freeBuffers
private void freeBuffers()
This method should be called along with (or instead of) normal close. After calling this method, no further reads should be tried. Method will try to recycle read buffers (if any).
-
canModifyBuffer
protected final boolean canModifyBuffer()
Method that can be used to see if we can actually modify the underlying buffer. This is the case if we are managing the buffer, but not if it was just given to us.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(char[] cbuf) throws java.io.IOException- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int start, int len) throws java.io.IOException- Specified by:
readin classjava.io.Reader- Throws:
java.io.IOException
-
loadMore
private boolean loadMore(int available) throws java.io.IOException- Parameters:
available- Number of "unused" bytes in the input buffer- Returns:
- True, if enough bytes were read to allow decoding of at least one full character; false if EOF was encountered instead.
- Throws:
java.io.IOException
-
readBytes
protected final int readBytes() throws java.io.IOException- Throws:
java.io.IOException
-
readBytesAt
protected final int readBytesAt(int offset) throws java.io.IOException- Throws:
java.io.IOException
-
reportInvalidInitial
private void reportInvalidInitial(int mask, int offset) throws java.io.IOException- Throws:
java.io.IOException
-
reportInvalidOther
private void reportInvalidOther(int mask, int offset) throws java.io.IOException- Throws:
java.io.IOException
-
reportUnexpectedEOF
private void reportUnexpectedEOF(int gotBytes, int needed) throws java.io.IOException- Throws:
java.io.IOException
-
reportBounds
protected void reportBounds(char[] cbuf, int start, int len) throws java.io.IOException- Throws:
java.io.IOException
-
reportStrangeStream
protected void reportStrangeStream() throws java.io.IOException- Throws:
java.io.IOException
-
-