org.activemath.util
Class MyUTF8XMLWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.activemath.util.MyUTF8XMLWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable
Direct Known Subclasses:
ProtectedUTF8XMLWriter

public class MyUTF8XMLWriter
extends Writer

An XMLWriter that encodes characters in UTF-8. Methods are not synchronized: wrap this in a SyncXMLWriter if you need to use this concurrently from multiple threads. This version has been entirely retaken from com.jclark.xml.output.UTF8XMLWriter which took the lineSeparator from the system properties hence was not settable. Rewrote every line-separator expression as protected method.

Version:
$Revision: 1.1 $ $Date: 2001/03/27 15:39:32 $

Field Summary
static char escapedLineSeparator
           
 String lineSeparator
           
static int MINIMIZE_EMPTY_ELEMENTS
           
static int MINIMIZE_EMPTY_ELEMENTS_HTML
           
 String sysLineSeparator
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
MyUTF8XMLWriter(OutputStream out)
          Create an XML writer that will write in UTF-8 to the specified OutputStream with the default options.
MyUTF8XMLWriter(OutputStream out, int options)
          Create an XML writer that will write in UTF-8 to the specified OutputStream with the specified options.
 
Method Summary
 void attribute(String name, String value)
           
 void cdataSection(String content)
           
 void characterReference(int n)
           
 void close()
           
 void comment(String body)
           
 void endAttribute()
           
 void endElement(String name)
           
 void endReplacementText()
           
 void entityReference(boolean isParam, String name)
           
 void flush()
           
 void markup(String str)
           
 void newLine()
          Adds up a newLine as defined by the lineSeparator variable.
 void processingInstruction(String target, String data)
           
 void startAttribute(String name)
           
 void startElement(String name)
           
 void startReplacementText()
           
 void write(char c)
           
 void write(char[] cbuf, int off, int len)
           
 void write(String str)
           
 void write(String str, int off, int len)
           
protected  void writeRaw(String str)
          This method is the core writing mechanism.
 void writeUTF8(byte[] buf, int off, int len)
           
 
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

sysLineSeparator

public String sysLineSeparator

lineSeparator

public String lineSeparator

escapedLineSeparator

public static final char escapedLineSeparator
See Also:
Constant Field Values

MINIMIZE_EMPTY_ELEMENTS

public static final int MINIMIZE_EMPTY_ELEMENTS
See Also:
Constant Field Values

MINIMIZE_EMPTY_ELEMENTS_HTML

public static final int MINIMIZE_EMPTY_ELEMENTS_HTML
See Also:
Constant Field Values
Constructor Detail

MyUTF8XMLWriter

public MyUTF8XMLWriter(OutputStream out,
                       int options)
Create an XML writer that will write in UTF-8 to the specified OutputStream with the specified options.


MyUTF8XMLWriter

public MyUTF8XMLWriter(OutputStream out)
Create an XML writer that will write in UTF-8 to the specified OutputStream with the default options.

Method Detail

writeUTF8

public void writeUTF8(byte[] buf,
                      int off,
                      int len)
               throws IOException
Throws:
IOException

write

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

write

public void write(char c)
           throws IOException
Throws:
IOException

write

public void write(String str)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

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

writeRaw

protected void writeRaw(String str)
                 throws IOException
This method is the core writing mechanism. No other escape than the necessary ones for UTF-8. Calling it with < or > will probably invalidate the output xml.

Throws:
IOException

startElement

public void startElement(String name)
                  throws IOException
Throws:
IOException

attribute

public void attribute(String name,
                      String value)
               throws IOException
Throws:
IOException

startAttribute

public void startAttribute(String name)
                    throws IOException
Throws:
IOException

endAttribute

public void endAttribute()
                  throws IOException
Throws:
IOException

endElement

public void endElement(String name)
                throws IOException
Throws:
IOException

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws IOException
Throws:
IOException

comment

public void comment(String body)
             throws IOException
Throws:
IOException

entityReference

public void entityReference(boolean isParam,
                            String name)
                     throws IOException
Throws:
IOException

characterReference

public void characterReference(int n)
                        throws IOException
Throws:
IOException

cdataSection

public void cdataSection(String content)
                  throws IOException
Throws:
IOException

markup

public void markup(String str)
            throws IOException
Throws:
IOException

startReplacementText

public void startReplacementText()
                          throws IOException
Throws:
IOException

endReplacementText

public void endReplacementText()
                        throws IOException
Throws:
IOException

flush

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

close

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

newLine

public void newLine()
             throws IOException
Adds up a newLine as defined by the lineSeparator variable. This method is also called by any newLine printing as all newLines transmitted are escaped (at least the escaped ones).

Throws:
IOException