Class XmlStreamWriter

java.lang.Object
java.io.Writer
org.apache.commons.io.output.XmlStreamWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class XmlStreamWriter extends Writer
Character stream that handles all the necessary work to figure out the charset encoding of the XML document written to the stream.

To build an instance, use XmlStreamWriter.Builder.

Since:
2.0
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • builder

      public static XmlStreamWriter.Builder builder()
      Constructs a new XmlStreamWriter.Builder.
      Returns:
      a new XmlStreamWriter.Builder.
      Since:
      2.12.0
    • close

      public void close() throws IOException
      Closes the underlying writer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException - if an error occurs closing the underlying writer
    • detectEncoding

      private void detectEncoding(char[] cbuf, int off, int len) throws IOException
      Detects the encoding.
      Parameters:
      cbuf - the buffer to write the characters from
      off - The start offset
      len - The number of characters to write
      Throws:
      IOException - if an error occurs detecting the encoding
    • flush

      public void flush() throws IOException
      Flushes the underlying writer.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
      Throws:
      IOException - if an error occurs flushing the underlying writer
    • getDefaultEncoding

      public String getDefaultEncoding()
      Returns the default encoding.
      Returns:
      the default encoding
    • getEncoding

      public String getEncoding()
      Returns the detected encoding.
      Returns:
      the detected encoding
    • write

      public void write(char[] cbuf, int off, int len) throws IOException
      Writes the characters to the underlying writer, detecting encoding.
      Specified by:
      write in class Writer
      Parameters:
      cbuf - the buffer to write the characters from
      off - The start offset
      len - The number of characters to write
      Throws:
      IOException - if an error occurs detecting the encoding