Class UTF8Reader
java.lang.Object
java.io.Reader
com.fasterxml.jackson.dataformat.yaml.UTF8Reader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
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
FieldsModifier and TypeFieldDescriptionprivate final boolean
protected final byte[][]
protected static final ThreadLocal<SoftReference<byte[][]>>
ThisThreadLocal
contains ajava.lang.ref.SoftRerefence
to a byte array used for holding content to decode(package private) int
Total read byte count; used for error reporting purposes(package private) int
Total read character count; used for error reporting purposesprotected byte[]
protected int
Pointed to the end marker, that is, position one after the last valid available byte.protected int
Pointer to the next available byte (if any), iff less thanmByteBufferEnd
private InputStream
protected int
Decoded first character of a surrogate pair, if one needs to be bufferedprivate char[]
private static final int
-
Constructor Summary
ConstructorsConstructorDescriptionUTF8Reader
(byte[] buf, int ptr, int len, boolean autoClose) UTF8Reader
(InputStream in, boolean autoClose) -
Method Summary
Modifier and TypeMethodDescriptionprivate static byte[][]
void
close()
final void
This method should be called along with (or instead of) normal close.protected final InputStream
private boolean
loadMore
(int available) int
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 caseint
read
(char[] cbuf) int
read
(char[] cbuf, int start, int len) protected final int
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
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) Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, ready, reset, skip, transferTo
-
Field Details
-
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE- See Also:
-
_bufferRecycler
ThisThreadLocal
contains ajava.lang.ref.SoftRerefence
to a byte array used for holding content to decode -
_bufferHolder
protected final byte[][] _bufferHolder -
_inputSource
-
_autoClose
private final boolean _autoClose -
_inputBuffer
protected byte[] _inputBuffer -
_inputPtr
protected int _inputPtrPointer to the next available byte (if any), iff less thanmByteBufferEnd
-
_inputEnd
protected int _inputEndPointed to the end marker, that is, position one after the last valid available byte. -
_surrogate
protected int _surrogateDecoded first character of a surrogate pair, if one needs to be buffered -
_charCount
int _charCountTotal read character count; used for error reporting purposes -
_byteCount
int _byteCountTotal read byte count; used for error reporting purposes -
_tmpBuffer
private char[] _tmpBuffer
-
-
Constructor Details
-
UTF8Reader
-
UTF8Reader
public UTF8Reader(byte[] buf, int ptr, int len, boolean autoClose)
-
-
Method Details
-
_findBufferHolder
private static byte[][] _findBufferHolder() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-
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- Overrides:
read
in classReader
- Throws:
IOException
-
read
- Overrides:
read
in classReader
- Throws:
IOException
-
read
- Specified by:
read
in classReader
- Throws:
IOException
-
getStream
-
readBytes
Method for reading as many bytes from the underlying stream as possible (that fit in the buffer), to the beginning of the buffer.- Returns:
- Number of bytes read, if any; -1 for end-of-input.
- Throws:
IOException
-
readBytesAt
Method for reading as many bytes from the underlying stream as possible (that fit in the buffer considering offset), to the specified offset.- Returns:
- Number of bytes read, if any; -1 to indicate none available (that is, end of input)
- Throws:
IOException
-
freeBuffers
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). -
reportInvalidInitial
- Throws:
IOException
-
reportInvalidOther
- Throws:
IOException
-
reportUnexpectedEOF
- Throws:
IOException
-
loadMore
- 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:
IOException
-
reportBounds
- Throws:
IOException
-
reportStrangeStream
- Throws:
IOException
-