public class XmlStreamWriter
extends java.io.Writer
XmlStreamReader
Modifier and Type | Field and Description |
---|---|
private static int |
BUFFER_SIZE |
private java.lang.String |
defaultEncoding |
private java.lang.String |
encoding |
(package private) static java.util.regex.Pattern |
ENCODING_PATTERN |
private java.io.OutputStream |
out |
private java.io.Writer |
writer |
private java.io.StringWriter |
xmlPrologWriter |
Constructor and Description |
---|
XmlStreamWriter(java.io.File file)
Construct an new XML stream writer for the specified file
with a default encoding of UTF-8.
|
XmlStreamWriter(java.io.File file,
java.lang.String defaultEncoding)
Construct an new XML stream writer for the specified file
with the specified default encoding.
|
XmlStreamWriter(java.io.OutputStream out)
Construct an new XML stream writer for the specified output stream
with a default encoding of UTF-8.
|
XmlStreamWriter(java.io.OutputStream out,
java.lang.String defaultEncoding)
Construct an new XML stream writer for the specified output stream
with the specified default encoding.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the underlying writer.
|
private void |
detectEncoding(char[] cbuf,
int off,
int len)
Detect the encoding.
|
void |
flush()
Flush the underlying writer.
|
java.lang.String |
getDefaultEncoding()
Return the default encoding.
|
java.lang.String |
getEncoding()
Return the detected encoding.
|
void |
write(char[] cbuf,
int off,
int len)
Write the characters to the underlying writer, detecing encoding.
|
private static final int BUFFER_SIZE
private final java.io.OutputStream out
private final java.lang.String defaultEncoding
private java.io.StringWriter xmlPrologWriter
private java.io.Writer writer
private java.lang.String encoding
static final java.util.regex.Pattern ENCODING_PATTERN
public XmlStreamWriter(java.io.OutputStream out)
out
- The output streampublic XmlStreamWriter(java.io.OutputStream out, java.lang.String defaultEncoding)
out
- The output streamdefaultEncoding
- The default encoding if not encoding could be detectedpublic XmlStreamWriter(java.io.File file) throws java.io.FileNotFoundException
file
- The file to write tojava.io.FileNotFoundException
- if there is an error creating or
opening the filepublic XmlStreamWriter(java.io.File file, java.lang.String defaultEncoding) throws java.io.FileNotFoundException
file
- The file to write todefaultEncoding
- The default encoding if not encoding could be detectedjava.io.FileNotFoundException
- if there is an error creating or
opening the filepublic java.lang.String getEncoding()
public java.lang.String getDefaultEncoding()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Writer
java.io.IOException
- if an error occurs closing the underlying writerpublic void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.Writer
java.io.IOException
- if an error occurs flushing the underlying writerprivate void detectEncoding(char[] cbuf, int off, int len) throws java.io.IOException
cbuf
- the buffer to write the characters fromoff
- The start offsetlen
- The number of characters to writejava.io.IOException
- if an error occurs detecting the encodingpublic void write(char[] cbuf, int off, int len) throws java.io.IOException
write
in class java.io.Writer
cbuf
- the buffer to write the characters fromoff
- The start offsetlen
- The number of characters to writejava.io.IOException
- if an error occurs detecting the encoding