|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectkirk.io.sdl.SDLReader
This class is able to read SDL files into SDLDocument
s. To make
things as easy as possible, all you have to do is:
SDLDocument sdldocument = SDLReader.readSDL(<InputStream>);
(when reading from an InputStream
)
or
SDLDocument sdldocument = SDLReader.readSDLFile(<filename>);
(when reading from a file).
This also means you cannot instantiate this class yourself. If for some reason you
need to do this, extend this class. The constructor is protected.
Note that the SDL data must be encoded with UTF-16.
SDLDocument
Field Summary | |
protected int |
position
The position in the file. |
protected BufferedReader |
reader
The Reader the SDL document is read from. |
Constructor Summary | |
protected |
SDLReader(InputStream in)
Constructs a new SDLReader with the given input source to read
from. |
Method Summary | |
protected boolean |
checkEndTag(String tagname)
Reads characters from the current position in the reader until as many as the length of the end tag of the given tag name are read. |
protected boolean |
checkStartTag(String tagname)
Reads characters from the current position in the reader until as many as the length of the start tag of the given tag name are read. |
protected void |
close()
Closes the underlying stream. |
void |
finalize()
The finalize method. |
protected SDLReadException |
getException(String error)
Returns an SDLReadException with the given message, and some
other information, like the place it happened in the file. |
protected char |
read()
Reads and return the next character in the stream. |
protected SDLDataElement |
readDataElement()
Reads the data element at the current position in the file, and the contained value. |
protected SDLElement |
readElement()
Reads the element at the current position in the file, and the contained value. |
protected SDLNormalElement |
readNormalElement()
Reads the normal element at the current position in the file, and the contained value. |
static SDLDocument |
readSDL(InputStream in)
Reads the given SDL source into an SDL document, and returns that. |
protected SDLDocument |
readSDLDocument()
Reads the SDL document from the given source and returns it as an SDLDocument object. |
static SDLDocument |
readSDLFile(String filename)
Reads the given SDL file into an SDL document, and returns that. |
protected String |
readTagValue(String name)
Return the value inbetween the tag pair (start and end tag) with the given name. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected BufferedReader reader
Reader
the SDL document is read from.
protected int position
Constructor Detail |
protected SDLReader(InputStream in) throws IOException
SDLReader
with the given input source to read
from. If you wish to read from a file for example, supply a
new FileInputStream("filename")
. The input source should provide
raw byte data, which is converted to characters using UTF-16 encoding.
in
- The InputStream
to be read from.
IOException
- When an IO exception occurs. Mmmyeah.Method Detail |
protected SDLDocument readSDLDocument() throws IOException, SDLReadException
SDLDocument
object.
SDLDocument
tree with all the SDL data from the file.
IOException
- When IO errors occur (duh).
SDLReadException
- When the SDL is not correct.protected SDLElement readElement() throws IOException, SDLReadException
SDLElement
. The current position
in the file has to be followed by <element> or <data>.
IOException
- When IO errors occur (duh).
SDLReadException
- When the SDL is not correct.protected SDLNormalElement readNormalElement() throws IOException, SDLReadException
SDLDNormalElement
. The
current position in the file has NOT to be followed by <element>. This
has already been made sure in readElement()
.
This method will only read until the end of the value.
readElement()
will then check for the end tag.
IOException
- When IO errors occur (duh).
SDLReadException
- When the SDL is not correct.protected SDLDataElement readDataElement() throws IOException, SDLReadException
SDLDataElement
. The current
position in the file has NOT to be followed by <data>. This has already
been made sure in readElement()
.
This method will only read until the end of the value.
readElement()
will then check for the end tag.
IOException
- When IO errors occur (duh).
SDLReadException
- When the SDL is not correct.protected String readTagValue(String name) throws IOException, SDLReadException
name
- The name of the tag.
IOException
- When IO errors occur (duh).
SDLReadException
- When the SDL is not correct.protected boolean checkStartTag(String tagname) throws IOException, SDLReadException
tagname
- The tag name that the start tag that should be read of.
IOException
- When IO errors occur (duh).
SDLReadException
- When the end of the stream is reached during reading.protected boolean checkEndTag(String tagname) throws IOException, SDLReadException
tagname
- The tag name that the end tag that should be read of.
IOException
- When IO errors occur (duh).
SDLReadException
- When the end of the stream is reached during reading.protected char read() throws IOException, SDLReadException
IOException
- When IO errors occur (duh).
SDLReadException
- When an end of file is reached.protected SDLReadException getException(String error)
SDLReadException
with the given message, and some
other information, like the place it happened in the file.
error
- The error that occured.
SDLReadException
that signifies the given error.public void finalize()
Object.finalize()
protected void close() throws IOException
IOException
- When IO errors occur.public static SDLDocument readSDL(InputStream in) throws IOException, SDLReadException
in
- The InputStream
that provides the SDL to be read.
SDLDocument
that was constructed from the data from
the source.
IOException
- When IO errors occur.
SDLReadException
- When the data does not make up a correct SDL file.public static SDLDocument readSDLFile(String filename) throws IOException, SDLReadException
filename
- The SDL file to be read.
SDLDocument
that was constructed from the data in the
file.
IOException
- When IO errors occur.
SDLReadException
- When the file is not a correct SDL file.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |