nu.staldal.xodus
Class XMLCharacterEncoder

java.lang.Object
  extended by nu.staldal.xodus.XMLCharacterEncoder
All Implemented Interfaces:
java.io.Closeable, java.lang.Appendable

public class XMLCharacterEncoder
extends java.lang.Object
implements java.lang.Appendable, java.io.Closeable

Encodes output to an XML stream.

Inserts numeric character entities for characters which cannot be encoded in the specified encoding.

Note: Does not insert the gt, lt, qout, amp and apos entites.

The write and append methods will throw CharConversionException if character encoding or escaping fails.

This class is not thread safe.

This class implements all write methods of Writer, but does not extend Writer due to technical reasons.


Constructor Summary
XMLCharacterEncoder(java.lang.Appendable a, boolean isAppendable)
          Constructs an XMLCharacterEncoder which writes to the given Appendable.
XMLCharacterEncoder(java.io.OutputStream os, java.lang.String encoding)
          Constructs an XMLCharacterEncoder which writes to the given OutputStream.
XMLCharacterEncoder(java.io.Writer writer)
          Constructs an XMLCharacterEncoder which writes to the given Writer.
 
Method Summary
 java.lang.Appendable append(char c)
           
 java.lang.Appendable append(java.lang.CharSequence cs)
           
 java.lang.Appendable append(java.lang.CharSequence cs, int start, int end)
           
 void close()
           
 void finish()
           
 void write(char[] cbuf)
           
 void write(char[] cbuf, int off, int len)
           
 void write(int c)
           
 void write(java.lang.String str)
           
 void write(java.lang.String str, int off, int len)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLCharacterEncoder

public XMLCharacterEncoder(java.io.OutputStream os,
                           java.lang.String encoding)
                    throws java.io.UnsupportedEncodingException
Constructs an XMLCharacterEncoder which writes to the given OutputStream.

Parameters:
os - the OutputStream to write to.
encoding - the encoding to use.
Throws:
java.io.UnsupportedEncodingException - If the given encoding name is illegal or not available.

XMLCharacterEncoder

public XMLCharacterEncoder(java.io.Writer writer)
Constructs an XMLCharacterEncoder which writes to the given Writer. Does not encode or escape.

Parameters:
writer - the Writer to write to.

XMLCharacterEncoder

public XMLCharacterEncoder(java.lang.Appendable a,
                           boolean isAppendable)
Constructs an XMLCharacterEncoder which writes to the given Appendable. Does not encode or escape.

Parameters:
a - the Appendable to write to.
isAppendable - dummy parameter to avoid overloading problems
Method Detail

append

public java.lang.Appendable append(char c)
                            throws java.io.IOException
Specified by:
append in interface java.lang.Appendable
Throws:
java.io.IOException

append

public java.lang.Appendable append(java.lang.CharSequence cs)
                            throws java.io.IOException
Specified by:
append in interface java.lang.Appendable
Throws:
java.io.IOException

append

public java.lang.Appendable append(java.lang.CharSequence cs,
                                   int start,
                                   int end)
                            throws java.io.IOException
Specified by:
append in interface java.lang.Appendable
Throws:
java.io.IOException

write

public void write(int c)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(char[] cbuf)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.lang.String str)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.lang.String str,
                  int off,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

finish

public void finish()
            throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException