Top Description Fields Constructors Methods
com.fasterxml.jackson.dataformat.toml

public final Class UTF8Reader

extends Reader
Class Inheritance
Imports
java.io.*, com.fasterxml.jackson.core.io.IOContext

Optimized Reader that reads UTF-8 encoded content from an input stream. Content may come either from a static byte[] buffer or java.io.InputStream.

Field Summary

Modifier and TypeField and Description
private final boolean
private int
_byteCount

Total read byte count; used for error reporting purposes

private int
_charCount

Total read character count; used for error reporting purposes

private byte[]
private int
_inputEnd

Pointed to the end marker, that is, position one after the last valid available byte.

private int
_inputPtr

Pointer to the next available byte (if any), iff less than mByteBufferEnd

private InputStream
private final IOContext
_ioContext

IO context to use for returning input buffer, iff buffer is to be recycled when input ends.

private int
_surrogate

Decoded first character of a surrogate pair, if one needs to be buffered

private char[]
Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
private
UTF8Reader(IOContext ctxt, InputStream in, boolean autoClose, byte[] buf, int ptr, int end)

Method Summary

Modifier and TypeMethod and Description
protected final boolean
canModifyBuffer()

Method that can be used to see if we can actually modify the underlying buffer.

public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes the stream and releases any system resources associated with it.

public static UTF8Reader
construct(IOContext ctxt, InputStream in, boolean autoClose)

public static UTF8Reader
construct(byte[] buf, int ptr, int len)

private void
freeBuffers()

This method should be called along with (or instead of) normal close.

private boolean

Returns:

True, if enough bytes were read to allow decoding of at least one full character; false if EOF was encountered instead.
loadMore
(int
Number of "unused" bytes in the input buffer
available
)

public int
read()

Overrides java.io.Reader.read.

Reads a single character.

public int
read(char[]
Destination buffer
cbuf
)

Overrides java.io.Reader.read.

Reads characters into an array.

public int
read(final char[]
Destination buffer
cbuf
,
final int
Offset at which to start storing characters
start
,
int
Maximum number of characters to read
len
)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.

protected final int
protected final int
readBytesAt(int offset)

protected void
reportBounds(char[] cbuf, int start, int len)

private void
reportInvalidInitial(int mask, int offset)

private void
reportInvalidOther(int mask, int offset)

protected void
private void
reportUnexpectedEOF(int gotBytes, int needed)

Inherited from java.io.Reader:
markmarkSupportednullReaderreadreadyresetskiptransferTo

Field Detail

_autoCloseback to summary
private final boolean _autoClose
_byteCountback to summary
private int _byteCount

Total read byte count; used for error reporting purposes

_charCountback to summary
private int _charCount

Total read character count; used for error reporting purposes

_inputBufferback to summary
private byte[] _inputBuffer
_inputEndback to summary
private int _inputEnd

Pointed to the end marker, that is, position one after the last valid available byte.

_inputPtrback to summary
private int _inputPtr

Pointer to the next available byte (if any), iff less than mByteBufferEnd

_inputSourceback to summary
private InputStream _inputSource
_ioContextback to summary
private final IOContext _ioContext

IO context to use for returning input buffer, iff buffer is to be recycled when input ends.

_surrogateback to summary
private int _surrogate

Decoded first character of a surrogate pair, if one needs to be buffered

_tmpBufferback to summary
private char[] _tmpBuffer

Constructor Detail

UTF8Readerback to summary
private UTF8Reader(IOContext ctxt, InputStream in, boolean autoClose, byte[] buf, int ptr, int end)

Method Detail

canModifyBufferback to summary
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.

closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Doc from java.io.Reader.close.

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
constructback to summary
public static UTF8Reader construct(IOContext ctxt, InputStream in, boolean autoClose)
constructback to summary
public static UTF8Reader construct(byte[] buf, int ptr, int len)
freeBuffersback to summary
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).

loadMoreback to summary
private boolean loadMore(int available) throws IOException
Parameters
available:int

Number of "unused" bytes in the input buffer

Returns:boolean

True, if enough bytes were read to allow decoding of at least one full character; false if EOF was encountered instead.

readback to summary
public int read() throws IOException

Overrides java.io.Reader.read.

Doc from java.io.Reader.read.

Reads a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Subclasses that intend to support efficient single-character input should override this method.

Returns:int

The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readback to summary
public int read(char[] cbuf) throws IOException

Overrides java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If the length of cbuf is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
cbuf:char[]

Destination buffer

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readback to summary
public int read(final char[] cbuf, final int start, int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
cbuf:char[]

Destination buffer

start:int

Offset at which to start storing characters

len:int

Maximum number of characters to read

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readBytesback to summary
protected final int readBytes() throws IOException
readBytesAtback to summary
protected final int readBytesAt(int offset) throws IOException
reportBoundsback to summary
protected void reportBounds(char[] cbuf, int start, int len) throws IOException
reportInvalidInitialback to summary
private void reportInvalidInitial(int mask, int offset) throws IOException
reportInvalidOtherback to summary
private void reportInvalidOther(int mask, int offset) throws IOException
reportStrangeStreamback to summary
protected void reportStrangeStream() throws IOException
reportUnexpectedEOFback to summary
private void reportUnexpectedEOF(int gotBytes, int needed) throws IOException