Documentation of 'javolution37.javolution.io.Utf8ByteBufferWriter' Java class
Utf8ByteBufferWriter
javolution37.javolution.io

Class 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.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.

    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
      void close()
      Closes and resets this writer for reuse.
      void flush()
      Flushes the stream (this method has no effect, the data is always directly written to the ByteBuffer).
      void reset()
      Resets the internal state of this object to its default values.
      Utf8ByteBufferWriter setByteBuffer(java.nio.ByteBuffer byteBuffer)
      Sets the byte buffer to use for writing until this writer is closed.
      void write(char c)
      Writes a single character.
      void write(char[] cbuf, int off, int len)
      Writes a portion of an array of characters.
      void write(java.lang.CharSequence csq)
      Writes the specified character sequence.
      void write(int code)
      Writes a character given its 31-bits Unicode.
      void write(java.lang.String str, int off, int len)
      Writes a portion of a string.
      • Methods inherited from class java.io.Writer

        append, append, append, write, write
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Utf8ByteBufferWriter

        public Utf8ByteBufferWriter()
        Default constructor.
    • Method Detail

      • setByteBuffer

        public Utf8ByteBufferWriter setByteBuffer(java.nio.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:
        java.lang.IllegalStateException - if this writer is being reused and it has not been closed or reset.
      • write

        public void write(char c)
                   throws java.io.IOException
        Writes a single character. This method supports 16-bits character surrogates.
        Parameters:
        c - char the 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.IOException
        Writes a character given its 31-bits Unicode.
        Overrides:
        write in class java.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.IOException
        Writes a portion of an array of characters.
        Specified by:
        write in class java.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.IOException
        Writes a portion of a string.
        Overrides:
        write in class java.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.IOException
        Writes 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.IOException
        Flushes the stream (this method has no effect, the data is always directly written to the ByteBuffer).
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class java.io.Writer
        Throws:
        java.io.IOException - if an I/O error occurs.
      • close

        public void close()
                   throws java.io.IOException
        Closes and resets this writer for reuse.
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in class java.io.Writer
        Throws:
        java.io.IOException - if an I/O error occurs
      • reset

        public void reset()
        Description copied from interface: Reusable
        Resets the internal state of this object to its default values.
        Specified by:
        reset in interface Reusable

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.