uxparser
Class XWriter

java.lang.Object
  extended by java.io.Writer
      extended by uxparser.XWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class XWriter
extends java.io.Writer

XWriter is a specialized Writer that provides support for generating an XML output stream.


Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
XWriter(java.io.File file)
          Construct writer for specified file.
XWriter(java.io.OutputStream out)
          Construct writer for specified output stream.
 
Method Summary
 XWriter attr(java.lang.String name, java.lang.String value)
          Write an attribute pair name="value" where the value is written using safe().
 void close()
           
 void flush()
           
 XWriter indent(int indent)
          Write the specified number of spaces.
 boolean isZipped()
          Return if this XWriter is being used to generate a PKZIP file containing the XML document.
 XWriter nl()
          Write a newline character and return this.
 XWriter prolog()
          This write the standard prolog <?xml version="1.0" encoding="UTF-8"?>
 XWriter safe(int c, boolean escapeWhitespace)
          Convenience for XWriter.safe(this, c, escapeWhitespace).
 XWriter safe(java.lang.String s)
          Convenience for XWriter.safe(this, s, true).
 XWriter safe(java.lang.String s, boolean escapeWhitespace)
          Convenience for XWriter.safe(this, s, escapeWhitespace).
static void safe(java.io.Writer out, int c, boolean escapeWhitespace)
          Write a "safe" character.
static void safe(java.io.Writer out, java.lang.String s, boolean escapeWhitespace)
          This writes each character in the string to the output stream using the safe(Writer, int, boolean) method.
 void setZipped(boolean zipped)
          If set to true, then XWriter generates a compressed PKZIP file with one entry called "file.xml".
 XWriter w(boolean x)
          Write the specified boolean and return this.
 XWriter w(char x)
          Write the specified char and return this.
 XWriter w(double x)
          Write the specified double and return this.
 XWriter w(float x)
          Write the specified float and return this.
 XWriter w(int x)
          Write the specified int and return this.
 XWriter w(long x)
          Write the specified long and return this.
 XWriter w(java.lang.Object x)
          Write the specified Object and return this.
 void write(char[] buf)
           
 void write(char[] buf, 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

XWriter

public XWriter(java.io.File file)
        throws java.io.IOException
Construct writer for specified file.

Throws:
java.io.IOException

XWriter

public XWriter(java.io.OutputStream out)
        throws java.io.IOException
Construct writer for specified output stream.

Throws:
java.io.IOException
Method Detail

w

public XWriter w(java.lang.Object x)
Write the specified Object and return this.


w

public final XWriter w(boolean x)
Write the specified boolean and return this.


w

public final XWriter w(char x)
Write the specified char and return this.


w

public final XWriter w(int x)
Write the specified int and return this.


w

public final XWriter w(long x)
Write the specified long and return this.


w

public final XWriter w(float x)
Write the specified float and return this.


w

public final XWriter w(double x)
Write the specified double and return this.


nl

public final XWriter nl()
Write a newline character and return this.


indent

public final XWriter indent(int indent)
Write the specified number of spaces.


attr

public final XWriter attr(java.lang.String name,
                          java.lang.String value)
Write an attribute pair name="value" where the value is written using safe().


prolog

public XWriter prolog()
This write the standard prolog <?xml version="1.0" encoding="UTF-8"?>


safe

public final XWriter safe(java.lang.String s,
                          boolean escapeWhitespace)
Convenience for XWriter.safe(this, s, escapeWhitespace).


safe

public final XWriter safe(java.lang.String s)
Convenience for XWriter.safe(this, s, true).


safe

public final XWriter safe(int c,
                          boolean escapeWhitespace)
Convenience for XWriter.safe(this, c, escapeWhitespace).


safe

public static void safe(java.io.Writer out,
                        java.lang.String s,
                        boolean escapeWhitespace)
                 throws java.io.IOException
This writes each character in the string to the output stream using the safe(Writer, int, boolean) method.

Throws:
java.io.IOException

safe

public static void safe(java.io.Writer out,
                        int c,
                        boolean escapeWhitespace)
                 throws java.io.IOException
Write a "safe" character. This method will escape unsafe characters common in XML and HTML markup.

Throws:
java.io.IOException

isZipped

public boolean isZipped()
Return if this XWriter is being used to generate a PKZIP file containing the XML document. See setZipped()


setZipped

public void setZipped(boolean zipped)
               throws java.io.IOException
If set to true, then XWriter generates a compressed PKZIP file with one entry called "file.xml". This method cannot be called once bytes have been written. Zipped XWriters should only be used with stand alone files, it should not be used in streams mixed with other data. This feature is used in conjunction with XParser, which automatically detects plain text XML versuse PKZIP documents.

Throws:
java.io.IOException

write

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

write

public void write(char[] buf)
Overrides:
write in class java.io.Writer

write

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

write

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

write

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

flush

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

close

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