Class AoCharArrayWriter

java.lang.Object
java.io.Writer
java.io.CharArrayWriter
com.aoapps.lang.io.AoCharArrayWriter
All Implemented Interfaces:
Writable, Closeable, Flushable, Appendable, AutoCloseable

public class AoCharArrayWriter extends CharArrayWriter implements Writable
Provides direct access to the internal char[].
Author:
AO Industries, Inc.
  • Constructor Details

    • AoCharArrayWriter

      public AoCharArrayWriter()
    • AoCharArrayWriter

      public AoCharArrayWriter(int initialSize)
  • Method Details

    • getInternalCharArray

      public char[] getInternalCharArray()
    • getLength

      public long getLength()
      Description copied from interface: Writable
      Gets the number of characters represented by this Writable.
      Specified by:
      getLength in interface Writable
    • isFastToString

      public boolean isFastToString()
      Description copied from interface: Writable
      Checks if the writable will be able to be converted toString in an extremely efficient manner. This means without allocating any new buffer space or string copies. Callers should prefer toString over writeTo or appendTo when isFastToString returns true.

      Note: As of Java 1.7.0_06, String.substring(int, int) and related operations now copy underlying buffers.

      Specified by:
      isFastToString in interface Writable
    • toString

      public String toString(int off, int len)
      Converts a portion of the input data to a string.
      Returns:
      the string.
    • writeTo

      public void writeTo(Writer out, long off, long len) throws IOException
      Writes a portion of the contents of the buffer to another character stream.
      Specified by:
      writeTo in interface Writable
      Throws:
      IOException
    • writeTo

      public void writeTo(Encoder encoder, Writer out) throws IOException
      Description copied from interface: Writable
      Writes a streamed version of the object's String representation using the given encoder. What is written must be the same as if encoder.write(this.toString(), out) were called, but may be a much more efficient implementation.
      Specified by:
      writeTo in interface Writable
      Parameters:
      encoder - if null, no encoding is performed and will be the same as a call to Writable.writeTo(java.io.Writer)
      Throws:
      IOException
    • writeTo

      public void writeTo(Encoder encoder, Writer out, long off, long len) throws IOException
      Description copied from interface: Writable
      Writes a streamed version of the object's String representation using the given encoder. What is written must be the same as if encoder.write(this.toString(), off, len, out) were called, but may be a much more efficient implementation.
      Specified by:
      writeTo in interface Writable
      Parameters:
      encoder - if null, no encoding is performed and will be the same as a call to Writable.writeTo(java.io.Writer, long, long)
      Throws:
      IOException
    • trim

      public Writable trim() throws IOException
      Description copied from interface: Writable
      Trims the contents of this writable, as per rules of Strings.isWhitespace(int), returning the instance that represents this writable trimmed.

      It will most likely be faster to check Writable.isFastToString() and then trim the result of Writable.toString(). However, for non-fast-toString writables, this trim will be more efficient.

      Specified by:
      trim in interface Writable
      Throws:
      IOException