java.lang.Object
java.io.Reader
tools.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 TypeFieldDescriptionprotected final byte[][]protected static final ThreadLocal<SoftReference<byte[][]>>ThisThreadLocalcontains aSoftReferenceto a byte array used for holding content to decodeprotected byte[]protected intPointed to the end marker, that is, position one after the last valid available byte.protected intPointer to the next available byte (if any), iff less thanmByteBufferEndprotected intDecoded first character of a surrogate pair, if one needs to be buffered -
Constructor Summary
ConstructorsConstructorDescriptionUTF8Reader(byte[] buf, int ptr, int len, boolean autoClose) UTF8Reader(InputStream in, boolean autoClose) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()final voidThis method should be called along with (or instead of) normal close.protected final InputStreamintread()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 caseintread(char[] cbuf) intread(char[] cbuf, int start, int len) protected final intMethod for reading as many bytes from the underlying stream as possible (that fit in the buffer), to the beginning of the buffer.protected final intreadBytesAt(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 voidreportBounds(char[] cbuf, int start, int len) protected voidMethods inherited from class java.io.Reader
mark, markSupported, nullReader, read, ready, reset, skip, transferTo
-
Field Details
-
_bufferRecycler
ThisThreadLocalcontains aSoftReferenceto a byte array used for holding content to decode -
_bufferHolder
protected final byte[][] _bufferHolder -
_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
-
-
Constructor Details
-
UTF8Reader
-
UTF8Reader
public UTF8Reader(byte[] buf, int ptr, int len, boolean autoClose)
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein 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:
readin classReader- Throws:
IOException
-
read
- Overrides:
readin classReader- Throws:
IOException
-
read
- Specified by:
readin 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). -
reportBounds
- Throws:
IOException
-
reportStrangeStream
- Throws:
IOException
-