JavaScript is disabled on your browser.
javolution.io

Class UTF8ByteBufferWriter

  • All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable


    public final class UTF8ByteBufferWriter
    extends Writer 

    A UTF-8 java.nio.ByteBuffer 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. 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.

    Version:
    2.0, December 9, 2004
    Author:
    Jean-Marie Dautelle
    See Also:
    UTF8ByteBufferReader
    • Constructor Detail

      • UTF8ByteBufferWriter

        public UTF8ByteBufferWriter()
        Default constructor.
    • Method Detail

      • setOutput

        public UTF8ByteBufferWriter setOutput(ByteBuffer byteBuffer)
        Sets the byte buffer to use for writing until this writer is closed.
        Parameters:
        byteBuffer - the destination byte buffer.
        Returns:
        this UTF-8 writer.
        Throws:
        IllegalStateException - if this writer is being reused and it has not been closed or reset.
      • write

        public void write(char c)
         throws IOException 
        Writes a single character. This method supports 16-bits character surrogates.
        Parameters:
        c - char the character to be written (possibly a surrogate).
        Throws:
        IOException - if an I/O error occurs.
      • write

        public void write(int code)
         throws IOException 
        Writes a character given its 31-bits Unicode.
        Overrides:
        write in class Writer
        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 
        Writes a portion of an array of characters.
        Specified by:
        write in class Writer
        Parameters:
        cbuf - the array of characters.
        off - the offset from which to start writing characters.
        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 
        Writes a portion of a string.
        Overrides:
        write in class Writer
        Parameters:
        str - a String.
        off - the offset from which to start writing characters.
        len - the number of characters to write.
        Throws:
        IOException - if an I/O error occurs
      • write

        public void write(CharSequence csq)
         throws IOException 
        Writes the specified character sequence.
        Parameters:
        csq - the character sequence.
        Throws:
        IOException - if an I/O error occurs
      • flush

        public void flush()
         throws IOException 
        Flushes the stream (this method has no effect, the data is always directly written to the ByteBuffer).
        Specified by:
        flush in interface Flushable
        Specified by:
        flush in class Writer
        Throws:
        IOException - if an I/O error occurs.
      • reset

        public void reset()

Copyright © 2005-2013 Javolution. All Rights Reserved.

AltStyle によって変換されたページ (->オリジナル) /