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.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
  • Method Details

    • length

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

      public void newLine() throws IOException
      Description copied from interface: SimpleWriter
      Write a newline according to the characteristics of the target platform.
      Specified by:
      newLine in interface SimpleWriter
      Throws:
      IOException - if an error happens when writing.
    • 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) throws IOException
      Description copied from interface: SimpleWriter
      Write a character sequence.
      Specified by:
      write in interface SimpleWriter
      Parameters:
      s - the CharSequence.
      Throws:
      IOException - if an error happens when writing.
    • write

      public void write(char[] cbuf, int offset, int len) throws IOException
      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.
      Throws:
      IOException - if an error happens when writing.
    • write

      public void write(char c) throws IOException
      Description copied from interface: SimpleWriter
      Write a character.
      Specified by:
      write in interface SimpleWriter
      Parameters:
      c - the character.
      Throws:
      IOException - if an error happens when writing.
    • write

      public void write(int num) throws IOException
      Description copied from interface: SimpleWriter
      Write an integer.
      Specified by:
      write in interface SimpleWriter
      Parameters:
      num - the integer number.
      Throws:
      IOException - if an error happens when writing.