Class UTF8Reader
- java.lang.Object
-
- java.io.Reader
-
- com.fasterxml.jackson.dataformat.csv.impl.UTF8Reader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public final class UTF8Reader extends java.io.ReaderOptimized 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.
-
-
Constructor Summary
Constructors Constructor Description UTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, byte[] buf, int ptr, int len)UTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, java.io.InputStream in, boolean autoClose)UTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, java.io.InputStream in, boolean autoClose, byte[] buf, int ptr, int len)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanModifyBuffer()Method that can be used to see if we can actually modify the underlying buffer.voidclose()voidfreeBuffers()This method should be called along with (or instead of) normal close.protected java.io.InputStreamgetStream()intread()Although this method is implemented by the base class, AND it should never be called by parser code, let's still implement it bit more efficiently just in caseintread(char[] cbuf)intread(char[] cbuf, int start, int len)protected intreadBytes()Method for reading as many bytes from the underlying stream as possible (that fit in the buffer), to the beginning of the buffer.protected 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 voidreportDeferredInvalid()protected voidreportInvalidInitial(int mask, int outputDecoded)protected voidreportInvalidOther(int mask, int outputDecoded, int errorPosition)protected voidreportStrangeStream()protected voidreportUnexpectedEOF(int gotBytes, int needed)
-
-
-
Constructor Detail
-
UTF8Reader
public UTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, java.io.InputStream in, boolean autoClose, byte[] buf, int ptr, int len)
-
UTF8Reader
public UTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, byte[] buf, int ptr, int len)
-
UTF8Reader
public UTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, java.io.InputStream in, boolean autoClose)
-
-
Method Detail
-
canModifyBuffer
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.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOExceptionAlthough this method is implemented by the base class, AND it should never be called by parser code, let's still implement it bit more efficiently just in case- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(char[] cbuf) throws java.io.IOException- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int start, int len) throws java.io.IOException- Specified by:
readin classjava.io.Reader- Throws:
java.io.IOException
-
getStream
protected final java.io.InputStream getStream()
-
readBytes
protected final int readBytes() throws java.io.IOExceptionMethod for reading as many bytes from the underlying stream as possible (that fit in the buffer), to the beginning of the buffer.- Throws:
java.io.IOException
-
readBytesAt
protected final int readBytesAt(int offset) throws java.io.IOExceptionMethod 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
-
reportInvalidInitial
protected void reportInvalidInitial(int mask, int outputDecoded) throws java.io.IOException- Throws:
java.io.IOException
-
reportInvalidOther
protected void reportInvalidOther(int mask, int outputDecoded, int errorPosition) throws java.io.IOException- Throws:
java.io.IOException
-
reportDeferredInvalid
protected void reportDeferredInvalid() throws java.io.IOException- Throws:
java.io.IOException
-
reportUnexpectedEOF
protected void reportUnexpectedEOF(int gotBytes, int needed) throws java.io.IOException- Throws:
java.io.IOException
-
-