public class XMLStreamer
extends java.io.BufferedWriter
In addition to basic character and string writing operations, XMLStreamer inherits the newLine() method (from BufferedWriter) and supplies an indent(int) method to indent the current line to an indentation level. The number of tab spaces to use for each level of indentation may be set. XMLStreamer keeps track of the current output line number, for the sake of error reporting. XMLStreamer implements the Closeable interface by virtue of inheriting from BufferedWriter.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
encoding
The name of the character set used when encoding characters into bytes.
|
private boolean |
isStandardOutput
Secret flag to determine whether the wrapped stream is System.out,
used to block closing the standard output stream.
|
private int |
lineNumber
The current line number in the output file.
|
private java.lang.String |
tabString
The size of a single tabulation used for indentation.
|
Constructor and Description |
---|
XMLStreamer(java.io.File file,
java.lang.String encoding)
Creates an XMLStreamer writing to a file, using a specified character
encoding.
|
XMLStreamer(java.io.OutputStream stream,
java.lang.String encoding)
Creates an XMLStreamer writing to a basic OutputStream, using a specified
character encoding.
|
XMLStreamer(java.io.Writer writer,
java.lang.String encoding)
Creates an XMLStreamer writing to a character Writer, using a given
character encoding.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this XMLStreamer.
|
java.lang.String |
getEncoding()
Returns the character encoding used by this XMLStreamer.
|
int |
getLineNumber()
Returns the line number in the output stream.
|
java.lang.String |
getTabString()
Returns the current tabulation string.
|
void |
indent(int level)
Writes an indentation to the specified indentation level.
|
void |
newLine()
Writes a newline according to the operating system platform.
|
void |
setTabString(java.lang.String tabString)
Sets the current tabulation string.
|
private boolean isStandardOutput
private java.lang.String encoding
private java.lang.String tabString
private int lineNumber
public XMLStreamer(java.io.File file, java.lang.String encoding) throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException
file
- the output file.encoding
- the name of the character encoding.java.io.FileNotFoundException
- if the file cannot be opened.java.io.UnsupportedEncodingException
- if the character encoding is
not supported.public XMLStreamer(java.io.OutputStream stream, java.lang.String encoding) throws java.io.UnsupportedEncodingException
stream
- the basic OutputStream.encoding
- the name of the character encoding.java.io.UnsupportedEncodingException
- if the character encoding is not
supported.public XMLStreamer(java.io.Writer writer, java.lang.String encoding)
writer
- the character Writer.encoding
- the name of the character encoding.public java.lang.String getEncoding()
public java.lang.String getTabString()
public void setTabString(java.lang.String tabString)
tabString
- the new tabulation string.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.BufferedWriter
java.io.IOException
- if an I/O error occurs during closing.public void newLine() throws java.io.IOException
newLine
in class java.io.BufferedWriter
java.io.IOException
- if an output error occurs while writing.public void indent(int level) throws java.io.IOException
level
- the indentation level.java.io.IOException
- if an output error occurs while writing.public int getLineNumber()