kirk.io.sdl
Class ESDLWriter

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

public class ESDLWriter
extends Object

This class writes an ESDL description indicated by an SDLDocument to an OutputStream, using UTF-16. This means that the class will lay out the SDL data in a neatly ordened fashion. Currently no preference settings are available.

To make things as easy as possible, all you have to do is:

ESDLWriter.writeESDL(<SDLDocument>, <OutputStream>); (when writing to an OutputStream)
or
ESDLWriter.writeESDLFile(<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 ESDLWriter(OutputStream out)
          Constructs a new ESDLWriter with the given output source to write to.
 
Method Summary
protected  void close()
          Closes the underlying stream.
 void finalize()
          The finalize method.
protected  ESDLWriteException getException(String error)
          Returns an ESDLWriteException 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(int indentation, SDLDataElement element)
          Writes the given SDLDataElement to the output stream.
protected  void writeElement(int indentation, SDLElement element)
          Writes the given SDLElement to the output stream.
protected  void writeEndTag(int indentation, String tagname)
          Writes the given tagname as end tag to the stream, with the given indentation, and a linebreak.
static void writeESDL(SDLDocument document, OutputStream out)
          Writes the given SDLDocument to the given OutputStream.
static void writeESDLFile(SDLDocument document, String filename)
          Writes the given SDLDocument to file with the given filename.
protected  void writeFullTag(int indentation, String name, String value)
          Writes a tag pair with the given tag name and tag value to the stream.
protected  void writeLine(int indentation, String string, boolean newline)
          Writes a line to the output stream.
protected  void writeNewLine()
          Writes a newline character to the stream.
protected  void writeNormalElement(int indentation, SDLNormalElement element)
          Writes the given SDLNormalElement to the output stream.
protected  void writeSDLDocument(SDLDocument document)
          Writes the given SDLDocument to the output stream.
protected  void writeStartTag(int indentation, String tagname, boolean newline)
          Writes the given tagname as start tag to the stream, with the given indentation, and a linebreak if requested.
protected  void writeTab()
          Writes a tab character 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

ESDLWriter

protected ESDLWriter(OutputStream out)
              throws IOException
Constructs a new ESDLWriter 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,
                                ESDLWriteException
Writes the given SDLDocument to the output stream.

Parameters:
document - The SDLDocument to write.
Throws:
IOException - When IO errors occur.
ESDLWriteException - When ESDL errors occur.

writeElement

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

Parameters:
indentation - The amount of tabs used for indentation.
element - The SDLElement to write.
Throws:
IOException - When IO errors occur.
ESDLWriteException - When ESDL errors occur.

writeNormalElement

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

Parameters:
indentation - The amount of tabs used for indentation.
element - The SDLNormalElement to write.
Throws:
IOException - When IO errors occur.
ESDLWriteException - When ESDL errors occur.

writeDataElement

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

Parameters:
indentation - The amount of tabs used for indentation.
element - The SDLDataElement to write.
Throws:
IOException - When IO errors occur.

writeStartTag

protected void writeStartTag(int indentation,
                             String tagname,
                             boolean newline)
                      throws IOException
Writes the given tagname as start tag to the stream, with the given indentation, and a linebreak if requested.

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

writeEndTag

protected void writeEndTag(int indentation,
                           String tagname)
                    throws IOException
Writes the given tagname as end tag to the stream, with the given indentation, and a linebreak.

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

writeFullTag

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

Parameters:
indentation - The amount of tabs before the tag pair.
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.

writeLine

protected void writeLine(int indentation,
                         String string,
                         boolean newline)
                  throws IOException
Writes a line to the output stream. It consists of indentation, a string, and a newline.

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

writeNewLine

protected void writeNewLine()
                     throws IOException
Writes a newline character to the stream.

Throws:
IOException - When IO errors occur.

writeTab

protected void writeTab()
                 throws IOException
Writes a tab character to the stream.

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 ESDLWriteException getException(String error)
Returns an ESDLWriteException with the given message, and some other information, like the place it happened in the file.

Parameters:
error - The error that occured.
Returns:
The ESDLWriteException 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.

writeESDL

public static void writeESDL(SDLDocument document,
                             OutputStream out)
                      throws IOException,
                             ESDLWriteException
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.
ESDLWriteException - When ESDL errors occur.

writeESDLFile

public static void writeESDLFile(SDLDocument document,
                                 String filename)
                          throws IOException,
                                 ESDLWriteException
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.
ESDLWriteException - When ESDL errors occur.