nu.staldal.xodus
Class XMLCharacterEncoder

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

public class XMLCharacterEncoder
extends java.io.Writer

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 methods will throw CharConversionException if character encoding or escaping fails.

This class is not thread safe.


Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
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
 void close()
           
 void disableEscaping()
          Disable escaping with XML character entites.
 void enableEscaping()
          Enable escaping with XML character entites.
 void finish()
          Finish encoding and flush output, without closing underlaying stream.
 void flush()
           
 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.io.Writer
append, append, append
 
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.
Method Detail

enableEscaping

public void enableEscaping()
Enable escaping with XML character entites. In effect until disableEscaping() is invoked.

Note: Escaping is disabled at start.


disableEscaping

public void disableEscaping()
Disable escaping with XML character entites. In effect until enableEscaping() is invoked.

Note: Escaping is disabled at start.


write

public void write(int c)
           throws java.io.IOException
Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

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

write

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

write

public void write(java.lang.String str)
           throws java.io.IOException
Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

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

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class java.io.Writer
Throws:
java.io.IOException

finish

public void finish()
            throws java.io.IOException
Finish encoding and flush output, without closing underlaying stream.

Throws:
java.io.IOException

close

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