Class BufferSimpleWriter

java.lang.Object
io.sf.carte.util.BufferSimpleWriter
All Implemented Interfaces:
SimpleWriter

public class BufferSimpleWriter extends Object implements SimpleWriter
An implementation of SimpleWriter backed by a StringBuilder.
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Initializes a BufferSimpleWriter with an initial buffer capacity of 128 characters.
    BufferSimpleWriter(int initialCapacity)
    Initializes a BufferSimpleWriter with an initial buffer capacity of initialCapacity characters.
    Initializes a BufferSimpleWriter with the given buffer.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    Get the StringBuilder buffer.
    int
    Get the count of the characters in this object.
    void
    Write a newline according to the characteristics of the target platform.
    Return the contents of this buffer as a String.
    void
    Remove the last character found in this buffer, if any.
    void
    unwrite(int numChars)
    Remove the last numChars characters found in this buffer.
    void
    write(char c)
    Write a character.
    void
    write(char[] cbuf, int offset, int len)
    Write a sequence of characters from an array.
    void
    write(int num)
    Write an integer.
    void
    Write a character sequence.

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details Link icon

    • BufferSimpleWriter Link icon

      public BufferSimpleWriter()
      Initializes a BufferSimpleWriter with an initial buffer capacity of 128 characters.
    • BufferSimpleWriter Link icon

      public BufferSimpleWriter(int initialCapacity)
      Initializes a BufferSimpleWriter with an initial buffer capacity of initialCapacity characters.
      Parameters:
      initialCapacity - the buffer initial capacity.
    • BufferSimpleWriter Link icon

      public BufferSimpleWriter(StringBuilder buffer)
      Initializes a BufferSimpleWriter with the given buffer.
      Parameters:
      buffer - the StringBuilder buffer.
  • Method Details Link icon

    • getBuffer Link icon

      public StringBuilder getBuffer()
      Get the StringBuilder buffer.
      Returns:
      the buffer.
    • length Link icon

      public int length()
      Get the count of the characters in this object.
      Returns:
      the count of the characters.
    • newLine Link icon

      public void newLine()
      Description copied from interface: SimpleWriter
      Write a newline according to the characteristics of the target platform.
      Specified by:
      newLine in interface SimpleWriter
    • toString Link icon

      public String toString()
      Return the contents of this buffer as a String.
      Overrides:
      toString in class Object
      Returns:
      the contents of this buffer.
    • unwrite Link icon

      public void unwrite()
      Remove the last character found in this buffer, if any.
    • unwrite Link icon

      public void unwrite(int numChars)
      Remove the last numChars characters found in this buffer.

      If numChars is larger than the length of this buffer, removes all its contents.

      Parameters:
      numChars - the number of characters to remove.
    • write Link icon

      public void write(CharSequence s)
      Description copied from interface: SimpleWriter
      Write a character sequence.
      Specified by:
      write in interface SimpleWriter
      Parameters:
      s - the CharSequence.
    • write Link icon

      public void write(char[] cbuf, int offset, int len)
      Description copied from interface: SimpleWriter
      Write a sequence of characters from an array.
      Specified by:
      write in interface SimpleWriter
      Parameters:
      cbuf - the character array.
      offset - the offset to start writing.
      len - the number of characters to write from the array.
    • write Link icon

      public void write(char c)
      Description copied from interface: SimpleWriter
      Write a character.
      Specified by:
      write in interface SimpleWriter
      Parameters:
      c - the character.
    • write Link icon

      public void write(int num)
      Description copied from interface: SimpleWriter
      Write an integer.
      Specified by:
      write in interface SimpleWriter
      Parameters:
      num - the integer number.