public class XMLWriter extends Writer
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 atleast 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.| Constructor and Description |
|---|
XMLWriter(Writer writer)
Creates the instance of
XMLWriter |
XMLWriter(Writer writer,
int size)
Creates the instnace of
XMLWriter. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the stream, flushing it first.
|
void |
flush()
Flush the stream.
|
protected Writer |
getWriter()
Returns underlying
Writer |
void |
reset()
Reset this Writer.
|
void |
setWriter(Writer writer)
Set the given
Writer. |
void |
setWriter(Writer writer,
int size)
Set the given
Writer |
void |
write(char[] cbuf)
Write an array of characters.
|
void |
write(char[] cbuf,
int off,
int len)
Write a portion of an array of characters.
|
void |
write(int c)
Write a single character.
|
void |
write(String str)
Write a string.
|
void |
write(String str,
int off,
int len)
Write a portion of a string.
|
public XMLWriter(Writer writer)
XMLWriterpublic XMLWriter(Writer writer, int size)
XMLWriter.
atleast buffers the input to the
size specified.public void write(int c)
throws IOException
Subclasses that intend to support efficient single-character output should override this method.
write in class Writerc - int specifying a character to be written.IOException - If an I/O error occurspublic void write(char[] cbuf)
throws IOException
write in class Writercbuf - Array of characters to be writtenIOException - If an I/O error occurspublic void write(char[] cbuf,
int off,
int len)
throws IOException
write in class Writercbuf - Array of charactersoff - Offset from which to start writing characterslen - Number of characters to writeIOException - If an I/O error occurspublic void write(String str, int off, int len) throws IOException
write in class Writerstr - A Stringoff - Offset from which to start writing characterslen - Number of characters to writeIOException - If an I/O error occurspublic void write(String str) throws IOException
write in class Writerstr - String to be writtenIOException - If an I/O error occurspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class WriterIOException - If an I/O error occurspublic void flush()
throws IOException
flush in interface Flushableflush in class WriterIOException - If an I/O error occurspublic void reset()
public void setWriter(Writer writer)
Writer.Writer - Writer.public void setWriter(Writer writer, int size)
WriterWriter - Writer.int - Writer will buffer the character data size, after that data is written to stream.protected Writer getWriter()
WriterCopyright © 2018–2021 mhoffrogge. All rights reserved.