Class UTF8Reader
- java.lang.Object
-
- java.io.Reader
-
- com.fasterxml.jackson.dataformat.yaml.UTF8Reader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Readable
public final class UTF8Reader extends java.io.Reader
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
Fields Modifier and Type Field Description protected byte[][]
_bufferHolder
protected static java.lang.ThreadLocal<java.lang.ref.SoftReference<byte[][]>>
_bufferRecycler
ThisThreadLocal
contains ajava.lang.ref.SoftRerefence
to a byte array used for holding content to decodeprotected byte[]
_inputBuffer
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 thanmByteBufferEnd
protected int
_surrogate
Decoded first character of a surrogate pair, if one needs to be buffered
-
Constructor Summary
Constructors Constructor Description UTF8Reader(byte[] buf, int ptr, int len, boolean autoClose)
UTF8Reader(java.io.InputStream in, boolean autoClose)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
freeBuffers()
This method should be called along with (or instead of) normal close.protected java.io.InputStream
getStream()
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 int
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 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)
protected void
reportStrangeStream()
-
-
-
Field Detail
-
_bufferRecycler
protected static final java.lang.ThreadLocal<java.lang.ref.SoftReference<byte[][]>> _bufferRecycler
ThisThreadLocal
contains ajava.lang.ref.SoftRerefence
to a byte array used for holding content to decode
-
_bufferHolder
protected final byte[][] _bufferHolder
-
_inputBuffer
protected byte[] _inputBuffer
-
_inputPtr
protected int _inputPtr
Pointer to the next available byte (if any), iff less thanmByteBufferEnd
-
_inputEnd
protected int _inputEnd
Pointed to the end marker, that is, position one after the last valid available byte.
-
_surrogate
protected int _surrogate
Decoded first character of a surrogate pair, if one needs to be buffered
-
-
Method Detail
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Reader
- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException
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 classjava.io.Reader
- Throws:
java.io.IOException
-
read
public int read(char[] cbuf) throws java.io.IOException
- Overrides:
read
in classjava.io.Reader
- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int start, int len) throws java.io.IOException
- Specified by:
read
in classjava.io.Reader
- Throws:
java.io.IOException
-
getStream
protected final java.io.InputStream getStream()
-
readBytes
protected final int readBytes() throws java.io.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:
- Number of bytes read, if any; -1 for end-of-input.
- Throws:
java.io.IOException
-
readBytesAt
protected final int readBytesAt(int offset) throws java.io.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:
- Number of bytes read, if any; -1 to indicate none available (that is, end of input)
- Throws:
java.io.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
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
-
-