Class UTF8Reader
java.lang.Object
java.io.Reader
com.fasterxml.jackson.dataformat.csv.impl.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 booleanprivate intTotal read byte count; used for error reporting purposesprivate intTotal read character count; used for error reporting purposesprivate intFlag that is set when a pending decode error has been detected; needed to properly handle deferred reporting.private byte[]private intPointed to the end marker, that is, position one after the last valid available byte.private intPointer to the next available byte (if any), iff less thanmByteBufferEndprivate InputStreamprivate final com.fasterxml.jackson.core.io.IOContextIO context to use for returning input buffer, iff buffer is to be recycled when input ends.private intDecoded first character of a surrogate pair, if one needs to be bufferedprivate char[] -
Constructor Summary
ConstructorsConstructorDescriptionUTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, byte[] buf, int ptr, int len) UTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, InputStream in, boolean autoClose) UTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, InputStream in, boolean autoClose, byte[] buf, int ptr, int len) -
Method Summary
Modifier and TypeMethodDescriptionprotected final booleanMethod that can be used to see if we can actually modify the underlying buffer.voidclose()final voidThis method should be called along with (or instead of) normal close.protected final InputStreamprivate booleanloadMore(int available) 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 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 voidprotected voidreportInvalidInitial(int mask, int outputDecoded) protected voidreportInvalidOther(int mask, int outputDecoded, int errorPosition) protected voidprotected voidreportUnexpectedEOF(int gotBytes, int needed) Methods inherited from class Reader
mark, markSupported, nullReader, of, read, readAllAsString, readAllLines, ready, reset, skip, transferTo
-
Field Details
-
_ioContext
private final com.fasterxml.jackson.core.io.IOContext _ioContextIO context to use for returning input buffer, iff buffer is to be recycled when input ends. -
_inputSource
-
_autoClose
private final boolean _autoClose -
_inputBuffer
private byte[] _inputBuffer -
_inputPtr
private int _inputPtrPointer to the next available byte (if any), iff less thanmByteBufferEnd -
_inputEnd
private int _inputEndPointed to the end marker, that is, position one after the last valid available byte. -
_surrogate
private int _surrogateDecoded first character of a surrogate pair, if one needs to be buffered -
_charCount
private int _charCountTotal read character count; used for error reporting purposes -
_byteCount
private int _byteCountTotal read byte count; used for error reporting purposes -
_decodeErrorOffset
private int _decodeErrorOffsetFlag that is set when a pending decode error has been detected; needed to properly handle deferred reporting. -
_tmpBuffer
private char[] _tmpBuffer
-
-
Constructor Details
-
UTF8Reader
public UTF8Reader(com.fasterxml.jackson.core.io.IOContext ctxt, 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
-
-
Method Details
-
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
- 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 parser 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.- 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). -
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
-
reportInvalidInitial
- Throws:
IOException
-
reportInvalidOther
protected void reportInvalidOther(int mask, int outputDecoded, int errorPosition) throws IOException - Throws:
IOException
-
reportDeferredInvalid
- Throws:
IOException
-
reportUnexpectedEOF
- Throws:
IOException
-