| UnicodeXMLEncoder.java |
/*
* $Id: UnicodeXMLEncoder.java,v 1.16 2003/07/07 07:59:12 znerd Exp $
*/
package org.znerd.xmlenc;
import java.io.IOException;
import java.io.Writer;
/**
* XML encoder for encodings that support all Unicode characters.
*
* <p />This encoder makes one call to either
* {@link Writer#write(int) Writer.write(int)} or
* {@link Writer#write(int) Writer.write(String)} per character (in
* {@link #text(Writer,String,boolean)}). This is why it is advised to use buffered
* {@link Writer} implementations.
*
* @version $Revision: 1.16 $ $Date: 2003/07/07 07:59:12 $
* @author Ernst de Haan (<a href="mailto:znerd@FreeBSD.org">znerd@FreeBSD.org</a>)
*/
final class UnicodeXMLEncoder extends XMLEncoder {
//-------------------------------------------------------------------------
// Class functions
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Class fields
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Constructor
//-------------------------------------------------------------------------
/**
* Constructs a new <code>UnicodeXMLEncoder</code> for the specified
* encoding.
*
* @param encoding
* the encoding, not <code>null</code>.
*
* @throws IllegalArgumentException
* if <code>encoding == null</code>.
*/
UnicodeXMLEncoder(String encoding)
throws IllegalArgumentException {
if (encoding == null) {
throw new IllegalArgumentException("encoding == null");
}
_encoding = encoding;
}
//-------------------------------------------------------------------------
// Fields
//-------------------------------------------------------------------------
/**
* The encoding. Cannot be <code>null</code>.
*/
private final String _encoding;
//-------------------------------------------------------------------------
// Methods
//-------------------------------------------------------------------------
public String getEncoding() {
return _encoding;
}
public void declaration(Writer out)
throws NullPointerException, IOException {
out.write("<?xml version=\"1.0\" encoding=\"");
out.write(_encoding);
out.write("\"?>");
}
public void text(Writer out, char c) throws IOException {
out.write(c);
}
}