| java.lang.Object java.io.Writer javolution.io.UTF8StreamWriter
UTF8StreamWriter | final public class UTF8StreamWriter extends Writer implements Reusable(Code) | | This class represents a UTF-8 stream writer.
This writer supports surrogate char pairs (representing
characters in the range [U+10000 .. U+10FFFF]). It can also be used
to write characters from their unicodes (31 bits) directly
(ref.
UTF8StreamWriter.write(int) ).
Instances of this class can be reused for different output streams
and can be part of a higher level component (e.g. serializer) in order
to avoid dynamic buffer allocation when the destination output changes.
Also wrapping using a java.io.BufferedWriter is unnescessary
as instances of this class embed their own data buffers.
Note: This writer is unsynchronized and always produces well-formed
UTF-8 sequences.
author: Jean-Marie Dautelle version: 2.0, December 9, 2004 |
Constructor Summary | |
public | UTF8StreamWriter() Creates a UTF-8 writer having a byte buffer of moderate capacity (2048). | public | UTF8StreamWriter(int capacity) Creates a UTF-8 writer having a byte buffer of specified capacity. |
Method Summary | |
public void | close() Closes and
UTF8StreamWriter.reset resets this writer for reuse. | public void | flush() Flushes the stream. | public void | reset() | public UTF8StreamWriter | setOutput(OutputStream out) Sets the output stream to use for writing until this writer is closed.
For example:[code]
Writer writer = new UTF8StreamWriter().setOutputStream(out);
[/code] is equivalent but writes faster than [code]
Writer writer = new j2me.io.OutputStreamWriter(out, "UTF-8");
[/code]
Parameters: out - the output stream. | public UTF8StreamWriter | setOutputStream(OutputStream out) | public void | write(char c) Writes a single character. | public void | write(int code) Writes a character given its 31-bits Unicode. | public void | write(char cbuf, int off, int len) Writes a portion of an array of characters. | public void | write(String str, int off, int len) Writes a portion of a string. | public void | write(CharSequence csq) Writes the specified character sequence. |
UTF8StreamWriter | public UTF8StreamWriter()(Code) | | Creates a UTF-8 writer having a byte buffer of moderate capacity (2048).
|
UTF8StreamWriter | public UTF8StreamWriter(int capacity)(Code) | | Creates a UTF-8 writer having a byte buffer of specified capacity.
Parameters: capacity - the capacity of the byte buffer. |
flush | public void flush() throws IOException(Code) | | Flushes 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.
throws: IOException - if an I/O error occurs. |
reset | public void reset()(Code) | | |
setOutput | public UTF8StreamWriter setOutput(OutputStream out)(Code) | | Sets the output stream to use for writing until this writer is closed.
For example:[code]
Writer writer = new UTF8StreamWriter().setOutputStream(out);
[/code] is equivalent but writes faster than [code]
Writer writer = new j2me.io.OutputStreamWriter(out, "UTF-8");
[/code]
Parameters: out - the output stream. this UTF-8 writer. throws: IllegalStateException - if this writer is being reused and it has not been UTF8StreamWriter.close closed or UTF8StreamWriter.reset reset. |
write | public void write(char c) throws IOException(Code) | | Writes a single character. This method supports 16-bits
character surrogates.
Parameters: c - char the character to be written (possiblya surrogate). throws: IOException - if an I/O error occurs. |
write | public void write(int code) throws IOException(Code) | | Writes a character given its 31-bits Unicode.
Parameters: code - the 31 bits Unicode of the character to be written. throws: IOException - if an I/O error occurs. |
write | public void write(char cbuf, int off, int len) throws IOException(Code) | | Writes a portion of an array of characters.
Parameters: cbuf - the array of characters. Parameters: off - the offset from which to start writing characters. Parameters: len - the number of characters to write. throws: IOException - if an I/O error occurs. |
write | public void write(String str, int off, int len) throws IOException(Code) | | Writes a portion of a string.
Parameters: str - a String. Parameters: off - the offset from which to start writing characters. Parameters: len - the number of characters to write. throws: IOException - if an I/O error occurs |
|
|