de.unibi.techfak.misc
Class GUIOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by de.unibi.techfak.misc.GUIOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class GUIOutputStream
extends java.io.OutputStream

This OutputStream is designed to reroute all output written to it to a JTextArea. It is strongly recommended to wrap this OutputStream with a PrintStream, thus not every character has to be output, but the graphical component is updated line by line.

This class comes with an internal buffer for storing data, which is filled by the method write(int), and is not flushed until it is full, or a "\n" has to be written, or the method write(byte[], int, int) is called.


Field Summary
private  byte[] buffer
          One block to hold the characters before they are send to the graphical component.
private  int filled
          The fill state of the buffer.
private  javax.swing.JTextArea textComp
          The JTextArea the output is redirected to.
 
Constructor Summary
GUIOutputStream(javax.swing.JTextArea tc)
          Constructs this class by taking a graphical component to which all stream data is output using calls to append(String).
 
Method Summary
 void flush()
          Forces the output of the internal buffer.
 void write(byte[] b, int offset, int len)
          Sets a new text for the graphical component by generating the text from flushing the internal buffer and the buffer given.
 void write(int b)
          The byte is buffered, until one block of bytes come together or this byte is a '\n' (new-line) character.
 
Methods inherited from class java.io.OutputStream
close, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

textComp

private javax.swing.JTextArea textComp
The JTextArea the output is redirected to.


buffer

private byte[] buffer
One block to hold the characters before they are send to the graphical component.


filled

private int filled
The fill state of the buffer.

Constructor Detail

GUIOutputStream

public GUIOutputStream(javax.swing.JTextArea tc)
                throws java.lang.NullPointerException
Constructs this class by taking a graphical component to which all stream data is output using calls to append(String).

Parameters:
tc - The graphical component the stream data are shown with.
Throws:
java.lang.NullPointerException - If tc=null
Method Detail

write

public void write(int b)
The byte is buffered, until one block of bytes come together or this byte is a '\n' (new-line) character. Then the buffer is flushed by calling this.write(byte[], int, int)

Specified by:
write in class java.io.OutputStream
Parameters:
b - The byte to output.
See Also:
write(byte[], int, int)

write

public void write(byte[] b,
                  int offset,
                  int len)
Sets a new text for the graphical component by generating the text from flushing the internal buffer and the buffer given.

Overrides:
write in class java.io.OutputStream
Parameters:
b - The byte buffer to output.
offset - The first byte in the buffer that is to output.
len - The number of bytes of the given buffer that are output.

flush

public void flush()
Forces the output of the internal buffer.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream