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

public final Class UTF8Reader

extends Reader
Class Inheritance
Imports
java.io.*, java.lang.ref.SoftReference

Optimized Reader that reads UTF-8 encoded content from an input stream. In addition to doing (hopefully) optimal conversion, it can also take array of "pre-read" (leftover) bytes; this is necessary when preliminary stream/reader is trying to figure out underlying character encoding.

Field Summary

Modifier and TypeField and Description
private final boolean
protected final byte[][]
protected static final ThreadLocal<SoftReference<byte[][]>>
_bufferRecycler

This ThreadLocal contains a java.lang.ref.SoftReference to a byte array used for holding content to decode

pack-priv int
_byteCount

Total read byte count; used for error reporting purposes

pack-priv int
_charCount

Total read character count; used for error reporting purposes

protected byte[]
protected int
_inputEnd

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

protected int
_inputPtr

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

private InputStream
protected int
_surrogate

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

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

Constructor Summary

AccessConstructor and Description
public
UTF8Reader(InputStream in, boolean autoClose)

public
UTF8Reader(byte[] buf, int ptr, int len, boolean autoClose)

Method Summary

Modifier and TypeMethod and Description
private static byte[][]
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 final void
freeBuffers()

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

protected final InputStream
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.

Although this method is implemented by the base class, AND it should never be called by Woodstox code, let's still implement it bit more efficiently just in case

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

Returns:

Number of bytes read, if any; -1 for end-of-input.
readBytes
()

Method for reading as many bytes from the underlying stream as possible (that fit in the buffer), to the beginning of the buffer.

protected final int

Returns:

Number of bytes read, if any; -1 to indicate none available (that is, end of input)
readBytesAt
(int offset)

Method for reading as many bytes from the underlying stream as possible (that fit in the buffer considering offset), to the specified 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
_bufferHolderback to summary
protected final byte[][] _bufferHolder
_bufferRecyclerback to summary
protected static final ThreadLocal<SoftReference<byte[][]>> _bufferRecycler

This ThreadLocal contains a java.lang.ref.SoftReference to a byte array used for holding content to decode

_byteCountback to summary
pack-priv int _byteCount

Total read byte count; used for error reporting purposes

_charCountback to summary
pack-priv int _charCount

Total read character count; used for error reporting purposes

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

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

_inputPtrback to summary
protected int _inputPtr

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

_inputSourceback to summary
private InputStream _inputSource
_surrogateback to summary
protected int _surrogate

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

_tmpBufferback to summary
private char[] _tmpBuffer
DEFAULT_BUFFER_SIZEback to summary
private static final int DEFAULT_BUFFER_SIZE

Constructor Detail

UTF8Readerback to summary
public UTF8Reader(InputStream in, boolean autoClose)
UTF8Readerback to summary
public UTF8Reader(byte[] buf, int ptr, int len, boolean autoClose)

Method Detail

_findBufferHolderback to summary
private static byte[][] _findBufferHolder()
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
freeBuffersback to summary
public final 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).

getStreamback to summary
protected final InputStream getStream()
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.

Although this method is implemented by the base class, AND it should never be called by Woodstox code, let's still implement it bit more efficiently just in case

Returns:int

Doc from java.io.Reader.read.

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:

Doc from java.io.Reader.read.

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

Method for reading as many bytes from the underlying stream as possible (that fit in the buffer), to the beginning of the buffer.

Returns:int

Number of bytes read, if any; -1 for end-of-input.

readBytesAtback to summary
protected final int readBytesAt(int offset) throws IOException

Method for reading as many bytes from the underlying stream as possible (that fit in the buffer considering offset), to the specified offset.

Returns:int

Number of bytes read, if any; -1 to indicate none available (that is, end of input)

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