Package org.apache.commons.io.output
Class XmlStreamWriter
- java.lang.Object
 - 
- java.io.Writer
 - 
- org.apache.commons.io.output.XmlStreamWriter
 
 
 
- 
- All Implemented Interfaces:
 java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public class XmlStreamWriter extends java.io.WriterCharacter 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:
 XmlStreamWriter.Builder,XmlStreamReader
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXmlStreamWriter.BuilderBuilds a newXmlStreamWriter. 
- 
Constructor Summary
Constructors Constructor Description XmlStreamWriter(java.io.File file)Deprecated.XmlStreamWriter(java.io.File file, java.lang.String defaultEncoding)Deprecated.XmlStreamWriter(java.io.OutputStream out)Deprecated.XmlStreamWriter(java.io.OutputStream out, java.lang.String defaultEncoding)Deprecated. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static XmlStreamWriter.Builderbuilder()Constructs a newXmlStreamWriter.Builder.voidclose()Closes the underlying writer.voidflush()Flushes the underlying writer.java.lang.StringgetDefaultEncoding()Returns the default encoding.java.lang.StringgetEncoding()Returns the detected encoding.voidwrite(char[] cbuf, int off, int len)Writes the characters to the underlying writer, detecting encoding. 
 - 
 
- 
- 
Constructor Detail
- 
XmlStreamWriter
@Deprecated public XmlStreamWriter(java.io.File file) throws java.io.FileNotFoundExceptionDeprecated.Constructs a new XML stream writer for the specified file with a default encoding of UTF-8.- Parameters:
 file- The file to write to- Throws:
 java.io.FileNotFoundException- if there is an error creating or opening the file
 
- 
XmlStreamWriter
@Deprecated public XmlStreamWriter(java.io.File file, java.lang.String defaultEncoding) throws java.io.FileNotFoundExceptionDeprecated.Constructs a new XML stream writer for the specified file with the specified default encoding.- Parameters:
 file- The file to write todefaultEncoding- The default encoding if not encoding could be detected- Throws:
 java.io.FileNotFoundException- if there is an error creating or opening the file
 
- 
XmlStreamWriter
@Deprecated public XmlStreamWriter(java.io.OutputStream out)
Deprecated.Constructs a new XML stream writer for the specified output stream with a default encoding of UTF-8.- Parameters:
 out- The output stream
 
- 
XmlStreamWriter
@Deprecated public XmlStreamWriter(java.io.OutputStream out, java.lang.String defaultEncoding)Deprecated.Constructs a new XML stream writer for the specified output stream with the specified default encoding.- Parameters:
 out- The output streamdefaultEncoding- The default encoding if not encoding could be detected
 
 - 
 
- 
Method Detail
- 
builder
public static XmlStreamWriter.Builder builder()
Constructs a newXmlStreamWriter.Builder.- Returns:
 - a new 
XmlStreamWriter.Builder. - Since:
 - 2.12.0
 
 
- 
close
public void close() throws java.io.IOExceptionCloses the underlying writer.- Specified by:
 closein interfacejava.lang.AutoCloseable- Specified by:
 closein interfacejava.io.Closeable- Specified by:
 closein classjava.io.Writer- Throws:
 java.io.IOException- if an error occurs closing the underlying writer
 
- 
flush
public void flush() throws java.io.IOExceptionFlushes the underlying writer.- Specified by:
 flushin interfacejava.io.Flushable- Specified by:
 flushin classjava.io.Writer- Throws:
 java.io.IOException- if an error occurs flushing the underlying writer
 
- 
getDefaultEncoding
public java.lang.String getDefaultEncoding()
Returns the default encoding.- Returns:
 - the default encoding
 
 
- 
getEncoding
public java.lang.String getEncoding()
Returns the detected encoding.- Returns:
 - the detected encoding
 
 
- 
write
public void write(char[] cbuf, int off, int len) throws java.io.IOExceptionWrites the characters to the underlying writer, detecting encoding.- Specified by:
 writein classjava.io.Writer- Parameters:
 cbuf- the buffer to write the characters fromoff- The start offsetlen- The number of characters to write- Throws:
 java.io.IOException- if an error occurs detecting the encoding
 
 - 
 
 -