Package org.apache.commons.io.output
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 Voodoo to figure out the charset encoding of the XML document written to the stream.- Since:
- 2.0
- See Also:
XmlStreamReader
-
-
Constructor Summary
Constructors Constructor Description XmlStreamWriter(File file)Constructs a new XML stream writer for the specified file with a default encoding of UTF-8.XmlStreamWriter(File file, String defaultEncoding)Constructs a new XML stream writer for the specified file with the specified default encoding.XmlStreamWriter(OutputStream out)Constructs a new XML stream writer for the specified output stream with a default encoding of UTF-8.XmlStreamWriter(OutputStream out, String defaultEncoding)Constructs a new XML stream writer for the specified output stream with the specified default encoding.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlying writer.voidflush()Flushes the underlying writer.StringgetDefaultEncoding()Returns the default encoding.StringgetEncoding()Returns the detected encoding.voidwrite(char[] cbuf, int off, int len)Writes the characters to the underlying writer, detecting encoding.
-
-
-
Constructor Detail
-
XmlStreamWriter
public XmlStreamWriter(OutputStream out)
Constructs a new XML stream writer for the specified output stream with a default encoding of UTF-8.- Parameters:
out- The output stream
-
XmlStreamWriter
public XmlStreamWriter(OutputStream out, String defaultEncoding)
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
-
XmlStreamWriter
public XmlStreamWriter(File file) throws FileNotFoundException
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:
FileNotFoundException- if there is an error creating or opening the file
-
XmlStreamWriter
public XmlStreamWriter(File file, String defaultEncoding) throws FileNotFoundException
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:
FileNotFoundException- if there is an error creating or opening the file
-
-
Method Detail
-
getEncoding
public String getEncoding()
Returns the detected encoding.- Returns:
- the detected encoding
-
getDefaultEncoding
public String getDefaultEncoding()
Returns the default encoding.- Returns:
- the default encoding
-
close
public void close() throws IOExceptionCloses the underlying writer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException- if an error occurs closing the underlying writer
-
flush
public void flush() throws IOExceptionFlushes the underlying writer.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException- if an error occurs flushing the underlying writer
-
write
public void write(char[] cbuf, int off, int len) throws IOExceptionWrites the characters to the underlying writer, detecting encoding.- Specified by:
writein classWriter- Parameters:
cbuf- the buffer to write the characters fromoff- The start offsetlen- The number of characters to write- Throws:
IOException- if an error occurs detecting the encoding
-
-