Class XMLOutputStream
public class XMLOutputStream extends OutputStream
{
// Fields
public static int COMPACT;
public static int PRETTY;
// Constructors
public XMLOutputStream( OutputStream out );
// Methods
public void addIndent(int offset);
public void close() throws IOException;
public void flush() throws IOException;
public int getOutputStyle();
public void setEncoding( String encoding, boolean littleendian,
boolean byteOrderMark ) throws IOException;
public void setOutputStyle(int style);
public void write( int c ) throws IOException;
public void writeChars( String str ) throws IOException;
public void writeIndent() throws IOException;
public void writeNewLine() throws IOException;
public void writeQualifiedName(Name n, Name ns) throws IOException;
public void writeQuotedString( String str ) throws IOException;
}
This class is an output stream writer that is specifically designed for XML including XML encoding, little endian files, XML namespaces, and white-space handling.
OutputStream
|
+--XMLOutputStream
public XMLOutputStream( OutputStream out );
Constructs the XMLOutputStream object as a standard UTF-8 output stream. A subsequent call to the setEncoding method will specify the correct character encoding that is required. Create an XMLOutputStream by using the createOutputStream method of the XMLInputStream class.
Parameter | Description |
out
| An output stream to use to create the XMLOutputStream.
|
public void addIndent(int offset);
Sets the relative indentation level (for example, addIndent(+1) or addIndent(-1)). The indent level controls what the writeIndent writes.
Return Value:
No return value.
Parameter | Description |
offset
| A signed value for the indentation level.
|
public void close() throws IOException;
Closes the XMLOutputStream and frees any system resources that are associated with the stream.
Return Value:
No return value.
Exceptions:
IOException
if an I/O error occurs.
public void flush() throws IOException;
Flushes the XMLOutputStream.
Return Value:
No return value.
Exceptions:
IOException
if an I/O error occurred.
public int getOutputStyle();
Retrieves the current output style for the output stream.
Return Value:
Returns either the COMPACT or the PRETTY output style.
public void setEncoding( String encoding, boolean littleendian,
boolean byteOrderMark ) throws IOException;
Defines the character encoding of the output stream.
Return Value:
No return value.
Parameter | Description |
encoding
| The type of character encoding. This may be one of the following formats:
- UTF-8
- Shift_JIS
- ISO-8859-1
- ISO-10646-UCS-4 (not yet supported)
- UCS-2
The default character encoding is ASCII.
|
littleendian
| Set this parameter to true to specify whether the stream is in little endian format.
|
byteOrderMark
| This flag is only relevant if the character encoding type is UCS-2. Otherwise, it is ignored.
|
Exceptions:
IOException
if the encoding type is not supported by the currently installed virtual machine.
public void setOutputStyle(int style);
Sets the output style for the output stream.
Return Value:
No return value.
Parameter | Description |
style
| The output style. This can be either PRETTY or COMPACT.
|
public void write( int c ) throws IOException;
Writes a character to the output stream according to the current write state. In order to avoid an extra conditional in every UCS-2 write, an extra state for a UCS-2 write operation that requires a ByteOrderMark is used. The ByteOrderMark is written only once at the beginning of the file.
Return Value:
No return value.
Parameter | Description |
c
| The character to write to the output stream.
|
Exceptions:
IOException
if there was an error writing to the stream.
public void writeChars( String str ) throws IOException;
Writes the given string to the output stream.
Return Value:
No return value.
Parameter | Description |
str
| The String to write to the output stream.
|
Exceptions:
IOException
if there was an error writing to the output stream.
public void writeIndent() throws IOException;
Writes the appropriate indent, according to the indentation level that is specified by the addIndent method. If the output style is COMPACT, the method performs no operation.
Return Value:
No return value.
Exceptions:
IOException
if there was an error writing to the output stream.
public void writeNewLine() throws IOException;
Writes a new line. If the output style is COMPACT, the method performs no operation.
Return Value:
No return value.
Exceptions:
IOException
if there was an error writing to the output stream.
public void writeQualifiedName(Name n, Name ns) throws IOException;
Writes out the fully qualified name, using the appropriate short name syntax.
Return Value:
No return value.
Parameter | Description |
n
| The Name being written.
|
ns
| The namespace that defines the context in which the name was defined.
|
Exceptions:
IOException
if there was an error writing to the stream.
public void writeQuotedString( String str ) throws IOException;
Writes out the string enclosed in quotation marks. This method uses quotation marks that are appropriate for the string (for example, if a string contains a single quotation mark ('), the method uses a double quotation mark ("), and so on).
Return Value:
No return value.
Parameter | Description |
str
| The String to write to the output stream.
|
- COMPACT
- An ouput style that specifies that no newline characters or tabs are used in the output stream.
- PRETTY
- The default output style. Newlines and tabs are used when writing to the output stream.