Class XMLWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public class XMLWriter
    extends java.io.Writer
    This class writes out the XML files, intercepting the output. First it collects all the output inside itself in a string. Then it adds the specified encoding declaration (or replaces the encoding) and writes out the file in the encoding.
    • Constructor Summary

      Constructors 
      Constructor Description
      XMLWriter​(java.io.File file, java.lang.String encoding, java.lang.String eol)
      Creates new XMLWriter.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Flushes the writer (which does the real write-out of data) and closes the real writer.
      void flush()
      Does the real write-out of the data, first adding/replacing encoding statement.
      void write​(char[] cbuf, int off, int len)
      Write a portion of an array of characters.
      • Methods inherited from class java.io.Writer

        append, append, append, nullWriter, write, write, write, write
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XMLWriter

        public XMLWriter​(java.io.File file,
                         java.lang.String encoding,
                         java.lang.String eol)
                  throws java.io.FileNotFoundException,
                         java.io.UnsupportedEncodingException
        Creates new XMLWriter.
        Parameters:
        fileName - file name to write to
        encoding - encoding to write a file in
        Throws:
        java.io.FileNotFoundException
        java.io.UnsupportedEncodingException
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Flushes the writer (which does the real write-out of data) and closes the real writer.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Writer
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Does the real write-out of the data, first adding/replacing encoding statement.
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class java.io.Writer
        Throws:
        java.io.IOException
      • write

        public void write​(char[] cbuf,
                          int off,
                          int len)
                   throws java.io.IOException
        Write a portion of an array of characters. Simply calls write(char[], int, int) of the internal StringWriter.
        Specified by:
        write in class java.io.Writer
        Parameters:
        cbuf - - Array of characters
        off - - Offset from which to start writing characters
        len - - Number of characters to write
        Throws:
        java.io.IOException - - If an I/O error occurs