de.zeigermann.xml

Class 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 XMLOutputStreamWriter 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

NEWLINE, NO_NEWLINE, depth, indent, nlAfterEmptyTag, nlAfterEndTag, nlAfterStartTag, prettyPrintMode, tabWidth, xmlDeclWritten

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, writeXMLDeclaration

Field Details

ENCODING_ISO_8859_1

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

ENCODING_ISO_LATIN1

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

ENCODING_STANDARD

public static String ENCODING_STANDARD
Name of standard encoding

ENCODING_UTF_16

public static String ENCODING_UTF_16
Name of UTF-16 encoding

ENCODING_UTF_8

public static String ENCODING_UTF_8
Name of UTF-8 encoding

encodingName

protected String encodingName

os

protected OutputStream os

Constructor Details

XMLOutputStreamWriter

public XMLOutputStreamWriter(OutputStream os)
            throws UnsupportedEncodingException
Parameters:

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, ...)

Method Details

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 interface XMLWriter

Copyright B) 2002-2004 Oliver Zeigermann. All Rights Reserved.