Class Utf8ByteBufferWriter
- java.lang.Object
-
- java.io.Writer
-
- javolution37.javolution.io.Utf8ByteBufferWriter
-
- All Implemented Interfaces:
- java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable, Reusable
public final class Utf8ByteBufferWriter extends java.io.Writer implements Reusable
This class represents a UTF-8
java.nio.ByteBufferwriter.This writer supports surrogate
charpairs (representing characters in the range [U+10000 .. U+10FFFF]). It can also be used to write characters from their unicodes (31 bits) directly (ref.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.BufferedWriteris unnescessary as instances of this class embed their own data buffers.Note: This writer is unsynchronized and always produces well-formed UTF-8 sequences.
- See Also:
Utf8ByteBufferReader
-
-
Constructor Summary
Constructors Constructor and Description Utf8ByteBufferWriter()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclose()Closes andresetsthis writer for reuse.voidflush()Flushes the stream (this method has no effect, the data is always directly written to theByteBuffer).voidreset()Resets the internal state of this object to its default values.Utf8ByteBufferWritersetByteBuffer(java.nio.ByteBuffer byteBuffer)Sets the byte buffer to use for writing until this writer is closed.voidwrite(char c)Writes a single character.voidwrite(char[] cbuf, int off, int len)Writes a portion of an array of characters.voidwrite(java.lang.CharSequence csq)Writes the specified character sequence.voidwrite(int code)Writes a character given its 31-bits Unicode.voidwrite(java.lang.String str, int off, int len)Writes a portion of a string.
-
-
-
Method Detail
-
setByteBuffer
public Utf8ByteBufferWriter setByteBuffer(java.nio.ByteBuffer byteBuffer)
Sets the byte buffer to use for writing until this writer is closed.
-
write
public void write(char c) throws java.io.IOExceptionWrites a single character. This method supports 16-bits character surrogates.- Parameters:
c-charthe character to be written (possibly a surrogate).- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(int code) throws java.io.IOExceptionWrites a character given its 31-bits Unicode.- Overrides:
writein classjava.io.Writer- Parameters:
code- the 31 bits Unicode of the character to be written.- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOExceptionWrites a portion of an array of characters.- Specified by:
writein classjava.io.Writer- Parameters:
cbuf- the array of characters.off- the offset from which to start writing characters.len- the number of characters to write.- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(java.lang.String str, int off, int len) throws java.io.IOExceptionWrites a portion of a string.- Overrides:
writein classjava.io.Writer- Parameters:
str- a String.off- the offset from which to start writing characters.len- the number of characters to write.- Throws:
java.io.IOException- if an I/O error occurs
-
write
public void write(java.lang.CharSequence csq) throws java.io.IOExceptionWrites the specified character sequence.- Parameters:
csq- the character sequence.- Throws:
java.io.IOException- if an I/O error occurs
-
flush
public void flush() throws java.io.IOExceptionFlushes the stream (this method has no effect, the data is always directly written to theByteBuffer).- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer- Throws:
java.io.IOException- if an I/O error occurs.
-
close
public void close() throws java.io.IOExceptionCloses andresetsthis writer for reuse.- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein classjava.io.Writer- Throws:
java.io.IOException- if an I/O error occurs
-
-
DMelt 3.0 © DataMelt by jWork.ORG