net.n3.nanoxml
Class ContentReader

java.lang.Object
  extended by java.io.Reader
      extended by net.n3.nanoxml.ContentReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

 class ContentReader
extends java.io.Reader

This reader reads data from another reader until a certain string is encountered.

Version:
$Name$, $Version$
Author:
Marc De Scheemaecker

Field Summary
private  java.lang.String charsReadTooMuch
          The characters that have been read too much.
private  int charsToGo
          The number of characters in the delimiter that stil need to be scanned.
private  char[] delimiter
          The delimiter that will indicate the end of the stream.
private  IXMLEntityResolver entityResolver
          The encapsulated entityResolver.
private  char escapeChar
          The escape char (& or %).
private  boolean pastInitialPrefix
          True if we are passed the initial prefix.
private  IXMLReader reader
          The encapsulated reader.
private  boolean useLowLevelReader
          True if the escape char (& or %) needs to be left untouched.
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
ContentReader(IXMLReader reader, IXMLEntityResolver entityResolver, char escapeChar, char[] delimiter, boolean useLowLevelReader, java.lang.String prefix)
          Creates the reader.
 
Method Summary
 void close()
          Skips remaining data and closes the stream.
protected  void finalize()
          Cleans up the object when it's destroyed.
 int read(char[] buffer, int offset, int size)
          Reads a block of data.
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reader

private IXMLReader reader
The encapsulated reader.


entityResolver

private IXMLEntityResolver entityResolver
The encapsulated entityResolver.


escapeChar

private char escapeChar
The escape char (& or %).


delimiter

private char[] delimiter
The delimiter that will indicate the end of the stream.


charsReadTooMuch

private java.lang.String charsReadTooMuch
The characters that have been read too much.


charsToGo

private int charsToGo
The number of characters in the delimiter that stil need to be scanned.


useLowLevelReader

private boolean useLowLevelReader
True if the escape char (& or %) needs to be left untouched.


pastInitialPrefix

private boolean pastInitialPrefix
True if we are passed the initial prefix.

Constructor Detail

ContentReader

ContentReader(IXMLReader reader,
              IXMLEntityResolver entityResolver,
              char escapeChar,
              char[] delimiter,
              boolean useLowLevelReader,
              java.lang.String prefix)
Creates the reader.

Parameters:
reader - the encapsulated reader
entityResolver - resolves entities
escapeChar - escape character (& or %)
delimiter - the delimiter, as a backwards string, that will indicate the end of the stream
useLowLevelReader - true if & needs to be left untouched; false if entities need to be processed
prefix - chars that are already read
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Cleans up the object when it's destroyed.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

read

public int read(char[] buffer,
                int offset,
                int size)
         throws java.io.IOException
Reads a block of data.

Specified by:
read in class java.io.Reader
Parameters:
buffer - where to put the read data
offset - first position in buffer to put the data
size - maximum number of chars to read
Returns:
the number of chars read, or -1 if at EOF
Throws:
java.io.IOException - if an error occurred reading the data

close

public void close()
           throws java.io.IOException
Skips remaining data and closes the stream.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader
Throws:
java.io.IOException - if an error occurred reading the data