bb.io
Class PrintWriterStoring

java.lang.Object
  extended by java.io.Writer
      extended by java.io.PrintWriter
          extended by bb.io.PrintWriterStoring
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class PrintWriterStoring
extends PrintWriter

PrintWriter subclass that writes all chars to an internal char buffer. This data is stored indefinately until it is retrieved and cleared by calling getString.

Motivation: this class is typically used for debugging/test purposes when output from a PrintWriter needs to be captured.

This class is multithread safe: every method is synchronized on Writer.lock.

Author:
Brent Boyer

Nested Class Summary
static class PrintWriterStoring.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
private  CharArrayWriter caw
           
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
PrintWriterStoring()
           
 
Method Summary
 String getString()
          Returns all the chars that have been written so far to this instance as a new String.
 
Methods inherited from class java.io.PrintWriter
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

caw

private final CharArrayWriter caw
Constructor Detail

PrintWriterStoring

public PrintWriterStoring()
Method Detail

getString

public String getString()
Returns all the chars that have been written so far to this instance as a new String. Side effect: before return, clears the internal char buffer.