org.apache.xmlrpc
Class XmlWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.OutputStreamWriter
          extended by org.apache.xmlrpc.XmlWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

 class XmlWriter
extends java.io.OutputStreamWriter

A XML writer intended for single-thread usage. If you feed it a ByteArrayInputStream, it may be necessary to call writer.flush() before calling buffer.toByteArray() to get the data written to your byte buffer.

Author:
Hannes Wallnoefer, Daniel L. Rall
See Also:
Tim Bray's Annotated XML Spec

Field Summary
protected static java.lang.String AMPERSAND_ENTITY
           
protected static org.apache.commons.codec.binary.Base64 base64Codec
           
protected static java.lang.String CLOSING_TAG_START
           
(package private)  DateTool dateTool
          Thread-safe wrapper for the DateFormat object used to parse date/time values.
protected static java.lang.String GREATER_THAN_ENTITY
           
(package private)  boolean hasWrittenProlog
          Whether the XML prolog has been written.
(package private) static java.lang.String ISO8859_1
          Java's name for the ISO-8859-1 encoding.
protected static java.lang.String LESS_THAN_ENTITY
           
protected static java.lang.String PROLOG_END
           
protected static java.lang.String PROLOG_START
           
protected static java.lang.String SINGLE_TAG_END
           
protected static TypeDecoder typeDecoder
          Class to delegate type decoding to.
(package private) static java.lang.String UTF16
          Java's name for the UTF-16 encoding.
(package private) static java.lang.String UTF8
          Java's name for the UTF-8 encoding.
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
XmlWriter(java.io.OutputStream out, java.lang.String enc)
          Creates a new instance.
 
Method Summary
protected static java.lang.String canonicalizeEncoding(java.lang.String javaEncoding)
          Deprecated. This method will not be visible in 2.0.
protected  void chardata(java.lang.String text)
          Writes text as PCDATA.
protected  void emptyElement(java.lang.String elem)
           
protected  void endElement(java.lang.String elem)
           
protected static void setTypeDecoder(TypeDecoder newTypeDecoder)
           
protected  void startElement(java.lang.String elem)
           
protected  void write(byte[] byteData)
          This is used to write out the Base64 output...
 void write(char c)
          A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.
 void write(char[] cbuf, int off, int len)
          A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.
 void write(java.lang.String str, int off, int len)
          A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.
 void writeObject(java.lang.Object obj)
          Writes the XML representation of a supported Java object type.
 
Methods inherited from class java.io.OutputStreamWriter
close, flush, getEncoding, write
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROLOG_START

protected static final java.lang.String PROLOG_START
See Also:
Constant Field Values

PROLOG_END

protected static final java.lang.String PROLOG_END
See Also:
Constant Field Values

CLOSING_TAG_START

protected static final java.lang.String CLOSING_TAG_START
See Also:
Constant Field Values

SINGLE_TAG_END

protected static final java.lang.String SINGLE_TAG_END
See Also:
Constant Field Values

LESS_THAN_ENTITY

protected static final java.lang.String LESS_THAN_ENTITY
See Also:
Constant Field Values

GREATER_THAN_ENTITY

protected static final java.lang.String GREATER_THAN_ENTITY
See Also:
Constant Field Values

AMPERSAND_ENTITY

protected static final java.lang.String AMPERSAND_ENTITY
See Also:
Constant Field Values

ISO8859_1

static final java.lang.String ISO8859_1
Java's name for the ISO-8859-1 encoding.

See Also:
Constant Field Values

UTF8

static final java.lang.String UTF8
Java's name for the UTF-8 encoding.

See Also:
Constant Field Values

UTF16

static final java.lang.String UTF16
Java's name for the UTF-16 encoding.

See Also:
Constant Field Values

base64Codec

protected static final org.apache.commons.codec.binary.Base64 base64Codec

typeDecoder

protected static TypeDecoder typeDecoder
Class to delegate type decoding to.


dateTool

DateTool dateTool
Thread-safe wrapper for the DateFormat object used to parse date/time values.


hasWrittenProlog

boolean hasWrittenProlog
Whether the XML prolog has been written.

Constructor Detail

XmlWriter

public XmlWriter(java.io.OutputStream out,
                 java.lang.String enc)
          throws java.io.UnsupportedEncodingException
Creates a new instance.

Parameters:
out - The stream to write output to.
enc - The encoding to using for outputing XML. Only UTF-8 and UTF-16 are supported. If another encoding is specified, UTF-8 will be used instead for widest XML parser interoperability.
Throws:
java.io.UnsupportedEncodingException - Since unsupported encodings are internally converted to UTF-8, this should only be seen as the result of an internal error.
Method Detail

canonicalizeEncoding

protected static java.lang.String canonicalizeEncoding(java.lang.String javaEncoding)
Deprecated. This method will not be visible in 2.0.

Tranforms a Java encoding to the canonical XML form (if a mapping is available).

Parameters:
javaEncoding - The name of the encoding as known by Java.
Returns:
The XML encoding (if a mapping is available); otherwise, the encoding as provided.

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.

Overrides:
write in class java.io.OutputStreamWriter
Throws:
java.io.IOException
See Also:
java.io.OutputStreamWriter.write(char[], int, int)

write

public void write(char c)
           throws java.io.IOException
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.

Throws:
java.io.IOException
See Also:
java.io.OutputStreamWriter.write(char)

write

public void write(java.lang.String str,
                  int off,
                  int len)
           throws java.io.IOException
A mostly pass-through implementation wrapping OutputStreamWriter.write() which assures that the XML prolog is written before any other data.

Overrides:
write in class java.io.OutputStreamWriter
Throws:
java.io.IOException
See Also:
java.io.OutputStreamWriter.write(String, int, int)

writeObject

public void writeObject(java.lang.Object obj)
                 throws XmlRpcException,
                        java.io.IOException
Writes the XML representation of a supported Java object type.

Parameters:
obj - The Object to write.
Throws:
XmlRpcException - Unsupported character data found.
java.io.IOException - Problem writing data.
java.lang.IllegalArgumentException - If a null parameter is passed to this method (not supported by the XML-RPC specification).

write

protected void write(byte[] byteData)
              throws java.io.IOException
This is used to write out the Base64 output...

Throws:
java.io.IOException

startElement

protected void startElement(java.lang.String elem)
                     throws java.io.IOException
Parameters:
elem -
Throws:
java.io.IOException

endElement

protected void endElement(java.lang.String elem)
                   throws java.io.IOException
Parameters:
elem -
Throws:
java.io.IOException

emptyElement

protected void emptyElement(java.lang.String elem)
                     throws java.io.IOException
Parameters:
elem -
Throws:
java.io.IOException

chardata

protected void chardata(java.lang.String text)
                 throws XmlRpcException,
                        java.io.IOException
Writes text as PCDATA.

Parameters:
text - The data to write.
Throws:
XmlRpcException - Unsupported character data found.
java.io.IOException - Problem writing data.

setTypeDecoder

protected static void setTypeDecoder(TypeDecoder newTypeDecoder)


Copyright 2001-2001-2005 Apache Software Foundation. All Rights Reserved.