kirk.io.sdl
Class SDLWriter

java.lang.Object
  extended bykirk.io.sdl.SDLWriter

public class SDLWriter
extends Object

This class writes an SDL description indicated by an SDLDocument to an OutputStream, using UTF-16. To make things as easy as possible, all you have to do is:

SDLWriter.writeSDL(<SDLDocument>, <OutputStream>); (when writing to an OutputStream)
or
SDLWriter.writeSDLFile(<SDLDocument>, <filename>); (when writing to 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.

Version:
1
Author:
Berend "Kirk" Wouda
See Also:
SDLDocument

Field Summary
protected  int position
          The position in the file.
protected  BufferedWriter writer
          The Writer the SDL document is written to.
 
Constructor Summary
protected SDLWriter(OutputStream out)
          Constructs a new SDLWriter with the given output source to write to.
 
Method Summary
protected  void close()
          Closes the underlying stream.
 void finalize()
          The finalize method.
protected  SDLWriteException getException(String error)
          Returns an SDLWriteException with the given message, and some other information, like the place it happened in the file.
protected  void write(String string)
          Writes a string to the output stream.
protected  void writeDataElement(SDLDataElement element)
          Writes the given SDLDataElement to the output stream.
protected  void writeElement(SDLElement element)
          Writes the given SDLElement to the output stream.
protected  void writeEndTag(String tagname)
          Writes the given tagname as end tag to the stream.
protected  void writeFullTag(String name, String value)
          Writes a tag pair with the given tag name and tag value to the stream.
protected  void writeNormalElement(SDLNormalElement element)
          Writes the given SDLNormalElement to the output stream.
static void writeSDL(SDLDocument document, OutputStream out)
          Writes the given SDLDocument to the given OutputStream.
protected  void writeSDLDocument(SDLDocument document)
          Writes the given SDLDocument to the output stream.
static void writeSDLFile(SDLDocument document, String filename)
          Writes the given SDLDocument to file with the given filename.
protected  void writeStartTag(String tagname)
          Writes the given tagname as start tag to the stream.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writer

protected BufferedWriter writer
The Writer the SDL document is written to.


position

protected int position
The position in the file. This is used to indicate where errors occur.

Constructor Detail

SDLWriter

protected SDLWriter(OutputStream out)
             throws IOException
Constructs a new SDLWriter with the given output source to write to. If you wish to write to a file for example, supply a new FileOutputStream("filename"). The output source will write raw byte data to the stream using UTF-16 encoding.

Parameters:
out - The OutputStream to be written to.
Throws:
IOException - When an IO exception occurs. Mmmyeah.
Method Detail

writeSDLDocument

protected void writeSDLDocument(SDLDocument document)
                         throws IOException,
                                SDLWriteException
Writes the given SDLDocument to the output stream.

Parameters:
document - The SDLDocument to write.
Throws:
IOException - When IO errors occur.
SDLWriteException - When SDL errors occur.

writeElement

protected void writeElement(SDLElement element)
                     throws IOException,
                            SDLWriteException
Writes the given SDLElement to the output stream.

Parameters:
element - The SDLElement to write.
Throws:
IOException - When IO errors occur.
SDLWriteException - When SDL errors occur.

writeNormalElement

protected void writeNormalElement(SDLNormalElement element)
                           throws IOException,
                                  SDLWriteException
Writes the given SDLNormalElement to the output stream.

Parameters:
element - The SDLNormalElement to write.
Throws:
IOException - When IO errors occur.
SDLWriteException - When SDL errors occur.

writeDataElement

protected void writeDataElement(SDLDataElement element)
                         throws IOException
Writes the given SDLDataElement to the output stream.

Parameters:
element - The SDLDataElement to write.
Throws:
IOException - When IO errors occur.

writeStartTag

protected void writeStartTag(String tagname)
                      throws IOException
Writes the given tagname as start tag to the stream.

Parameters:
tagname - The name of the start tag to be written.
Throws:
IOException - When IO errors occur.

writeEndTag

protected void writeEndTag(String tagname)
                    throws IOException
Writes the given tagname as end tag to the stream.

Parameters:
tagname - The name of the end tag to be written.
Throws:
IOException - When IO errors occur.

writeFullTag

protected void writeFullTag(String name,
                            String value)
                     throws IOException
Writes a tag pair with the given tag name and tag value to the stream.

Parameters:
name - The name of the tag pair to be written.
value - The value of the tag pair to be written.
Throws:
IOException - When IO errors occur.

write

protected void write(String string)
              throws IOException
Writes a string to the output stream.

Parameters:
string - The String to be written.
Throws:
IOException - When IO errors occur.

getException

protected SDLWriteException getException(String error)
Returns an SDLWriteException with the given message, and some other information, like the place it happened in the file.

Parameters:
error - The error that occured.
Returns:
The SDLWriteException that signifies the given error.

finalize

public void finalize()
The finalize method. It closes the stream.

See Also:
Object.finalize()

close

protected void close()
              throws IOException
Closes the underlying stream.

Throws:
IOException - When IO errors occur.

writeSDL

public static void writeSDL(SDLDocument document,
                            OutputStream out)
                     throws IOException,
                            SDLWriteException
Writes the given SDLDocument to the given OutputStream.

Parameters:
document - The SDLDocument that should be written.
out - The OutputStream that it should be written to.
Throws:
IOException - When IO errors occur.
SDLWriteException - When SDL errors occur.

writeSDLFile

public static void writeSDLFile(SDLDocument document,
                                String filename)
                         throws IOException,
                                SDLWriteException
Writes the given SDLDocument to file with the given filename.

Parameters:
document - The SDLDocument that should be written.
filename - The name of the file it should be written to.
Throws:
IOException - When IO errors occur.
SDLWriteException - When SDL errors occur.