de.uniba.wiai.lspi.util.console
Class MemoryOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by de.uniba.wiai.lspi.util.console.MemoryOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class MemoryOutputStream
extends OutputStream

This class can be used as OutputStream provided to a PrintStream that can be used to substitute System.out. The output is saved in a buffer that can be printed by invocation of printOutputTo(PrintStream) to the provided PrintStream. The content of the buffer can be obtained as String by the getOutput() method. clearBuffer() empties the buffer and all output, that has been saved before, is deleted.


Constructor Summary
MemoryOutputStream()
          Creates a new instance of MemoryOutputStream
 
Method Summary
 void clearBuffer()
          Clears the internal buffer of this output stream.
 String getOutput()
          Get the content of the internal buffer.
 void printOutputTo(PrintStream out)
          Print the content of the internal buffer to the given PrintStream out.
 void write(int b)
          Overwritten from OutputStream.
 
Methods inherited from class java.io.OutputStream
close, flush, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryOutputStream

public MemoryOutputStream()
Creates a new instance of MemoryOutputStream

Method Detail

clearBuffer

public void clearBuffer()
Clears the internal buffer of this output stream.


write

public void write(int b)
Overwritten from OutputStream. Writes the byte b to the internal buffer.

Specified by:
write in class OutputStream
Parameters:
b - The byte to write to the internal buffer.

getOutput

public String getOutput()
Get the content of the internal buffer.

Returns:
The output that has been saved before.

printOutputTo

public void printOutputTo(PrintStream out)
Print the content of the internal buffer to the given PrintStream out.

Parameters:
out - The PrintStream to print the saved output to.


Copyright © 2004-2008 Karsten Loesing, Sven Kaffille - Distributed and Mobile Systems Group, Lehrstuhl für Praktische Informatik, Universität Bamberg. All Rights Reserved.