APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.xml.internal.stream.writers

public Class XMLWriter

extends Writer
Class Inheritance
Imports
java.io.IOException, .Writer, com.sun.org.apache.xerces.internal.util.XMLStringBuffer

XMLWriter XMLWriter is not thread safe. For efficiency this writer buffers the input. Use flush() function to explicitly write the data to underlying stream. This writer is designed in such a way that it at least buffers the input to the size specified. Unless flush is called, it guarantees that data in chunks of size equal to or more than size specified will be written. XMLWriter instance can be reused. setWriter() internally clears the buffer and stores the reference to newly supplied Writer instance.
Author
Neeraj Bajaj Sun Microsystems, inc.

Field Summary

Modifier and TypeField and Description
private XMLStringBuffer
private static final boolean
private int
private static final int
private Writer
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public
XMLWriter(Writer writer)

Creates the instance of XMLWriter

public
XMLWriter(Writer writer, int size)

Creates the instance of XMLWriter.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Close the stream, flushing it first.

private void
conditionalWrite()

write the buffer data, if the buffer size has increased the size specified

private void
ensureOpen()

Check to make sure that the stream has not been closed

public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flush the stream.

protected Writer
getWriter()

Returns underlying Writer

public void
reset()

Reset this Writer.

public void
setWriter(Writer writer)

Set the given Writer.

public void
setWriter(Writer writer, int size)

Set the given Writer

public void
write(int
int specifying a character to be written.
c
)

Overrides java.io.Writer.write.

Write a single character.

public void
write(char[]
Array of characters to be written
cbuf
)

Overrides java.io.Writer.write.

Write an array of characters.

public void
write(char[]
Array of characters
cbuf
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Implements abstract java.io.Writer.write.

Write a portion of an array of characters.

public void
write(String
A String
str
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Overrides java.io.Writer.write.

Write a portion of a string.

public void
write(String
String to be written
str
)

Overrides java.io.Writer.write.

Write a string.

private void
writeBufferedData()

Write the data present in the buffer to the writer.

Inherited from java.io.Writer:
appendappendappendnullWriter

Field Detail

bufferback to summary
private XMLStringBuffer buffer
DEBUGback to summary
private static final boolean DEBUG
sizeback to summary
private int size
THRESHHOLD_LENGTHback to summary
private static final int THRESHHOLD_LENGTH
writerback to summary
private Writer writer

Constructor Detail

XMLWriterback to summary
public XMLWriter(Writer writer)

Creates the instance of XMLWriter

XMLWriterback to summary
public XMLWriter(Writer writer, int size)

Creates the instance of XMLWriter. at least buffers the input to the size specified.

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Close the stream, flushing it first. Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect.

Exceptions
IOException:
If an I/O error occurs
conditionalWriteback to summary
private void conditionalWrite() throws IOException

write the buffer data, if the buffer size has increased the size specified

ensureOpenback to summary
private void ensureOpen() throws IOException

Check to make sure that the stream has not been closed

flushback to summary
public void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flush the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

Exceptions
IOException:
If an I/O error occurs
getWriterback to summary
protected Writer getWriter()

Returns underlying Writer

resetback to summary
public void reset()

Reset this Writer. see @setWriter()

setWriterback to summary
public void setWriter(Writer writer)

Set the given Writer.

setWriterback to summary
public void setWriter(Writer writer, int size)

Set the given Writer

writeback to summary
public void write(int c) throws IOException

Overrides java.io.Writer.write.

Write a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.

Subclasses that intend to support efficient single-character output should override this method.

Parameters
c:int

int specifying a character to be written.

Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] cbuf) throws IOException

Overrides java.io.Writer.write.

Write an array of characters.

Parameters
cbuf:char[]

Array of characters to be written

Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Writer.write.

Write a portion of an array of characters.

Parameters
cbuf:char[]

Array of characters

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str, int off, int len) throws IOException

Overrides java.io.Writer.write.

Write a portion of a string.

Parameters
str:String

A String

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str) throws IOException

Overrides java.io.Writer.write.

Write a string.

Parameters
str:String

String to be written

Exceptions
IOException:
If an I/O error occurs
writeBufferedDataback to summary
private void writeBufferedData() throws IOException

Write the data present in the buffer to the writer. buffer is cleared after write operation.