de.zeigermann.xml
Class XMLOutputStreamWriter

java.lang.Object
  |
  +--java.io.Writer
        |
        +--java.io.FilterWriter
              |
              +--de.zeigermann.xml.XMLWriter
                    |
                    +--de.zeigermann.xml.XMLOutputStreamWriter

public class XMLOutputStreamWriter
extends XMLWriter

Adds XML export functionality to the underlying output stream. Formatting and encoding is done as straight forward as possible.
Everything you know better than this class must be done by you, e.g. you will have to tell XMLOutputStreamWriter where you wish to have newlines.In effect, no unexpected so called intelligent behavior is to be feared. Another effect is high speed.

Caution: Do not forget to call FilterWriter.flush() at the end of your exporting process as otherwise no data might be written. Warning: When using two byte encoding (e.g. UTF-16) underlying OutputStream can not savely be brought to string. Do not use ByteArrayOutputStream with two byte encoding, as XML declaration will be in single byte encoding (according to XML spec) and the rest will be in double byte totally confusing ByteArrayOutputStream encoding to string. If you want to have string output use XMLWriter filtering StringWriter or for convenience XMLStringWriter.

Author:
Olli Z.

Field Summary
static String ENCODING_ISO_8859_1
          Name of ISO-8859-1 encoding
static String ENCODING_ISO_LATIN1
          Alias for ISO-8859-1 encoding
static String ENCODING_STANDARD
          Name of standard encoding
static String ENCODING_UTF_16
          Name of UTF-16 encoding
static String ENCODING_UTF_8
          Name of UTF-8 encoding
protected  String encodingName
           
protected  OutputStream os
           
 
Fields inherited from class de.zeigermann.xml.XMLWriter
depth, indent, NEWLINE, nlAfterEmptyTag, nlAfterEndTag, nlAfterStartTag, NO_NEWLINE, prettyPrintMode, tabWidth, xmlDeclWritten
 
Fields inherited from class java.io.FilterWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
XMLOutputStreamWriter(OutputStream os)
          Creates a new output stream writer for XML export.
XMLOutputStreamWriter(OutputStream os, String encodingName)
          Creates a new output stream writer for XML export.
 
Method Summary
 String getEncodingName()
          Gets the name of the encoding as it would be inserted into the XML declaration.
 void writeXMLDeclaration()
          Writes XML delcaration using version 1.0 and encoding specified in constructor.
 
Methods inherited from class de.zeigermann.xml.XMLWriter
createEmptyTag, createEmptyTag, createEmptyTag, createEmptyTag, createEmptyTag, createEndTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, createStartTag, generateAndWriteElementWithCData, generateAndWriteElementWithCData, getNlAfterEmptyTag, getNlAfterEndTag, getNlAfterStartTag, getPrettyPrintMode, getTabWidth, isXMLDeclarationWritten, setNlAfterEmptyTag, setNlAfterEndTag, setNlAfterStartTag, setPrettyPrintMode, setTabWidth, setXMLDeclarationWritten, writeCData, writeComment, writeElementWithCData, writeElementWithPCData, writeEmptyElement, writeEmptyElement, writeEndTag, writeEndTag, writeNl, writePCData, writePI, writeProlog, writeStartTag, writeStartTag
 
Methods inherited from class java.io.FilterWriter
close, flush, write, write, write
 
Methods inherited from class java.io.Writer
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING_UTF_8

public static String ENCODING_UTF_8
Name of UTF-8 encoding


ENCODING_UTF_16

public static String ENCODING_UTF_16
Name of UTF-16 encoding


ENCODING_ISO_8859_1

public static String ENCODING_ISO_8859_1
Name of ISO-8859-1 encoding


ENCODING_STANDARD

public static String ENCODING_STANDARD
Name of standard encoding


ENCODING_ISO_LATIN1

public static String ENCODING_ISO_LATIN1
Alias for ISO-8859-1 encoding


os

protected OutputStream os

encodingName

protected String encodingName
Constructor Detail

XMLOutputStreamWriter

public XMLOutputStreamWriter(OutputStream os,
                             String encodingName)
                      throws UnsupportedEncodingException
Creates a new output stream writer for XML export.

Parameters:
encodingName - name of the encoding used to write XML as well as for the XML declataration (e.g. UTF-8, ISO-8859-1, ...)

XMLOutputStreamWriter

public XMLOutputStreamWriter(OutputStream os)
                      throws UnsupportedEncodingException
Creates a new output stream writer for XML export. Standard encoding will be used as found in ENCODING_STANDARD, which usually is UTF-8.

See Also:
XMLOutputStreamWriter(OutputStream, String)
Method Detail

getEncodingName

public String getEncodingName()
Gets the name of the encoding as it would be inserted into the XML declaration. OutputStreamWriter.getEncoding() may return something less verbose.

See Also:
OutputStreamWriter.getEncoding()

writeXMLDeclaration

public void writeXMLDeclaration()
                         throws IOException
Writes XML delcaration using version 1.0 and encoding specified in constructor. Caution: As XML declaration must be in plain text (no UNICODE) it will not be passed to writer, but directly to stream!

Overrides:
writeXMLDeclaration in class XMLWriter
IOException


Copyright 2002-2003 Oliver Zeigermann. All Rights Reserved.