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

    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

    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

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

    • BufferSimpleWriter

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

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

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

    • getBuffer

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

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

      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

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

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

      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

      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

      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

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

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