Package com.ctc.wstx.io
Class BaseReader
java.lang.Object
java.io.Reader
com.ctc.wstx.io.BaseReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
- Direct Known Subclasses:
AsciiReader
,ISOLatinReader
,UTF32Reader
,UTF8Reader
Simple basic class for optimized Readers Woodstox has; implements
"cookie-cutter" methods that are used by all actual implementations.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final char
DEL character is both the last ascii char, and illegal in xml 1.1.protected static final char
In xml 1.1, LSEP bit like \n, or \r.protected static final char
In xml 1.1, NEL (0x85) behaves much the way \n does (can be follow \r as part of the linefeedprotected 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
protected final ReaderConfig
private InputStream
private final boolean
Flag that indicates whether the read buffer is to be recycled when Reader is closed or not.protected char[]
protected static final char
protected static final char
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BaseReader
(ReaderConfig cfg, InputStream in, byte[] buf, int ptr, int len, boolean recycleBuffer) -
Method Summary
Modifier and TypeMethodDescriptionprotected final boolean
Method that can be used to see if we can actually modify the underlying buffer.void
close()
final void
This method should be called along with (or instead of) normal close.protected final InputStream
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 caseprotected 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) protected void
reportInvalidXml11
(int value, int bytePos, int charPos) protected void
abstract void
setXmlCompliancy
(int xmlVersion) Method that can be called to indicate the xml conformance used when reading content using this reader.
-
Field Details
-
NULL_CHAR
protected static final char NULL_CHAR- See Also:
-
NULL_BYTE
protected static final char NULL_BYTE- See Also:
-
CONVERT_NEL_TO
protected static final char CONVERT_NEL_TOIn xml 1.1, NEL (0x85) behaves much the way \n does (can be follow \r as part of the linefeed- See Also:
-
CONVERT_LSEP_TO
protected static final char CONVERT_LSEP_TOIn xml 1.1, LSEP bit like \n, or \r. Need to choose one as the result. Let's use \n, for simplicity- See Also:
-
CHAR_DEL
static final char CHAR_DELDEL character is both the last ascii char, and illegal in xml 1.1.- See Also:
-
mConfig
-
mIn
-
mByteBuffer
protected byte[] mByteBuffer -
mBytePtr
protected int mBytePtrPointer to the next available byte (if any), iff less thanmByteBufferEnd
-
mByteBufferEnd
protected int mByteBufferEndPointed to the end marker, that is, position one after the last valid available byte. -
mRecycleBuffer
private final boolean mRecycleBufferFlag that indicates whether the read buffer is to be recycled when Reader is closed or not. -
mTmpBuf
protected char[] mTmpBuf
-
-
Constructor Details
-
BaseReader
protected BaseReader(ReaderConfig cfg, InputStream in, byte[] buf, int ptr, int len, boolean recycleBuffer)
-
-
Method Details
-
setXmlCompliancy
public abstract void setXmlCompliancy(int xmlVersion) Method that can be called to indicate the xml conformance used when reading content using this reader. Some of the character validity checks need to be done at reader level, and sometimes they depend on xml level (for example, xml 1.1 has new linefeeds and both more and less restricted characters). -
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:
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
-
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). -
reportBounds
- Throws:
IOException
-
reportStrangeStream
- Throws:
IOException
-
reportInvalidXml11
- Throws:
IOException
-