Class MemoryWriter

java.lang.Object
java.io.Writer
com.nomagic.magicreport.engine.MemoryWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

@OpenApiAll public class MemoryWriter extends Writer
A character stream that collects its output in a memory.
Since:
Apr 30, 2008
  • Constructor Details

    • MemoryWriter

      public MemoryWriter()
      Create a new memory writer using the default initial string-buffer size.
    • MemoryWriter

      public MemoryWriter(int initialSize)
      Create a new memory writer using the specified initial string-buffer size.
      Parameters:
      initialSize - The number of char values that will fit into this buffer before it is automatically expanded
      Throws:
      IllegalArgumentException - If initialSize is negative
  • Method Details

    • write

      public void write(int c) throws IOException
      Write a single character.
      Overrides:
      write in class Writer
      Parameters:
      c - character
      Throws:
      IOException - If an I/O error occurs
    • write

      public void write(char[] cbuf, int off, int len) throws IOException
      Write a portion of an array of characters.
      Specified by:
      write in class Writer
      Parameters:
      cbuf - Array of characters
      off - Offset from which to start writing characters
      len - Number of characters to write
      Throws:
      IOException - If an I/O error occurs
    • write

      public void write(String str)
      Write a string.
      Overrides:
      write in class Writer
      Parameters:
      str - string to write
    • write

      public void write(String str, int off, int len)
      Write a portion of a string.
      Overrides:
      write in class Writer
      Parameters:
      str - String to be written
      off - Offset from which to start writing characters
      len - Number of characters to write
    • toString

      public String toString()
      Return the buffer's current value as a string.
      Overrides:
      toString in class Object
      Returns:
      current value as a string.
    • flush

      public void flush()
      Flush the stream.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
    • close

      public void close() throws IOException
      Close the stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException - If an I/O error occurs
    • getBuffer

      public StringBuilder getBuffer() throws IOException
      Return the string buffer itself.
      Returns:
      StringBuilder holding the current buffer value.
      Throws:
      IOException - the stream has been closed
    • size

      public long size()
      Return the size of current written data.
      Returns:
      writer size