Package eu.simuline.util.sgml
Class SGMLParser.Buffer
- java.lang.Object
-
- eu.simuline.util.sgml.SGMLParser.Buffer
-
- Enclosing class:
- SGMLParser
static class SGMLParser.Buffer extends Object
Class which buffers the read stream.
-
-
Field Summary
Fields Modifier and Type Field Description private char[]bufferArrayThe current buffer.private intendprivate intnewStartSet byreadArray(eu.simuline.util.sgml.SGMLParser.CharTester)and read bygetStartAndMove().private ReaderreaderThe reader buffered.private intstartThe first index inbufferArrayread in fromreaderbut not returned byreadArray(eu.simuline.util.sgml.SGMLParser.CharTester)orreadChar().
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) char[]getChars()Returns the buffer ofchars.(package private) intgetEnd()Get method forend.(package private) intgetStart()Get method forstart.(package private) intgetStartAndMove()(package private) booleanisEmpty()Returns whether this buffer is currently empty.(package private) booleanreachedEOS()Returns whether the end of the stream is reached.(package private) intreadArray(SGMLParser.CharTester charTester)Reads an array fromreader.(package private) intreadChar()Reads a singlecharand returns it.(package private) StringBufferreadStringBuffer(SGMLParser.CharTester charTester, String elementName)DescribereadStringBuffermethod here.
-
-
-
Field Detail
-
reader
private final Reader reader
The reader buffered.
-
bufferArray
private final char[] bufferArray
-
start
private int start
The first index inbufferArrayread in fromreaderbut not returned byreadArray(eu.simuline.util.sgml.SGMLParser.CharTester)orreadChar().
-
newStart
private int newStart
Set byreadArray(eu.simuline.util.sgml.SGMLParser.CharTester)and read bygetStartAndMove(). When invokingreadArray(eu.simuline.util.sgml.SGMLParser.CharTester)newStartis set tostartand increased by the number of read charactersincreases. ThengetStartAndMove()updatesstartaccording tonewStart.
-
end
private int end
The first index inbufferArraynot read fromreaderor-1if the end of the stream is reached. This means thatbufferArray[end]either does not exist or at least is not significant.
-
-
Constructor Detail
-
Buffer
Buffer(Reader reader, int length) throws IOException
Creates a newBufferfrom the given reader with the given size.- Parameters:
reader- theReaderto be buffered.length- the length of the buffer.- Throws:
IOException- if an error occurs
-
-
Method Detail
-
isEmpty
boolean isEmpty()
Returns whether this buffer is currently empty. When this is the case and someone tries to read further characters this will lead to a trial to read further pieces fromreader.- Returns:
- a
booleanvalue signifying whether this buffer is currently empty.
-
reachedEOS
boolean reachedEOS()
Returns whether the end of the stream is reached.- Returns:
- a
booleanspecifying whether the end of the stream is reached.
-
readChar
int readChar() throws IOExceptionReads a singlecharand returns it.- Returns:
- an
intvalue which is either the nextcharread in or-1which signifies the end of the stream. - Throws:
IOException- if an error occurs
-
readArray
int readArray(SGMLParser.CharTester charTester) throws IOException
Reads an array fromreader. As a side effect, writes the fieldnewStart. Also, if the portion ofbufferArrayto be read, i.e. betweenstartandend, is empty, a new portion is buffered.- Parameters:
charTester- aCharTesterwhich signifies when to end reading from the buffer.- Returns:
- an
intsignifying the number ofchars read or-1which signifies the end of the stream. It is read to the next < or, if there is none, to the end of the stream. Thus there is a difference between the return values-1and0. - Throws:
IOException- if an error occurs
-
readStringBuffer
StringBuffer readStringBuffer(SGMLParser.CharTester charTester, String elementName) throws IOException, SAXParseException
DescribereadStringBuffermethod here.- Parameters:
charTester- aCharTesterwhich determines the first character not read into the resultingStringBuffer.elementName- aStringwhich determines the element under consideration. This is only used for generating the message of aSAXParseException.Allowed values:
SGMLParser.START_TAG,SGMLParser.END_TAG,SGMLParser.PROC_INSTR,SGMLParser.ATTR_NAME,SGMLParser.WHITESP_IN_ATTRandSGMLParser.ATTR_VALUE. ****** comment and <!element missing.- Returns:
- a
StringBuffercontaining characters starting with the current one until onecharTesterreturnstrue. - Throws:
IOException- if an io-error occursSAXParseException- if the parser faces the end of the stream while scanning the current element.
-
getChars
char[] getChars()
Returns the buffer ofchars.- Returns:
- the
char[]bufferArray.
-
getStartAndMove
int getStartAndMove()
- Returns:
- the old
intvalue ofstart.
-
-