jess.tools
Class TextReader

java.lang.Object
  extended by java.io.Reader
      extended by jess.tools.TextReader
All Implemented Interfaces:
java.io.Closeable, java.io.Serializable, java.lang.Readable

public class TextReader
extends java.io.Reader
implements java.io.Serializable

A very simple reader, something like StringBufferReader but you can add text to it. Useful for creating GUIs in which you want Jess to continually read input from a text widget.

(C) 2013 Sandia Corporation

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
TextReader(boolean dontWait)
          Create a TextReader.
 
Method Summary
 void appendText(java.lang.String s)
          Add text to the internal buffer.
 int available()
          Find out if any input is waiting to be read.
 void clear()
          Remove all text from the internal buffer.
 void close()
          read() immediately returns EOF and subsequently throws IOException.
 int read()
          Read a character from the internal buffer.
 int read(char[] c)
          Read an array of characters from the internal buffer.
 int read(char[] c, int start, int count)
          Read part of an array of characters from the internal buffer.
 
Methods inherited from class java.io.Reader
mark, markSupported, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextReader

public TextReader(boolean dontWait)
Create a TextReader.

Parameters:
dontWait - If true, read() will return EOF (-1) immediately when its internal buffer is empty. If false, read() will block until more input becomes available.
Method Detail

read

public int read()
         throws java.io.IOException
Read a character from the internal buffer. Depending on the value of the dontWait parameter passed to the constructor, this method may block if no input is available.

Overrides:
read in class java.io.Reader
Returns:
The character or EOF (-1)
Throws:
java.io.IOException

read

public int read(char[] c)
         throws java.io.IOException
Read an array of characters from the internal buffer. Depending on the value of the dontWait parameter passed to the constructor, this method may block if no input is available.

Overrides:
read in class java.io.Reader
Returns:
The number of characters read.
Throws:
java.io.IOException

read

public int read(char[] c,
                int start,
                int count)
         throws java.io.IOException
Read part of an array of characters from the internal buffer. Depending on the value of the dontWait parameter passed to the constructor, this method may block if no input is available.

Specified by:
read in class java.io.Reader
Returns:
The number of characters read.
Throws:
java.io.IOException

close

public void close()
read() immediately returns EOF and subsequently throws IOException.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader

available

public int available()
Find out if any input is waiting to be read.

Returns:
True if internal buffer is not empty.

appendText

public void appendText(java.lang.String s)
Add text to the internal buffer. The text will become available for reading via read().

Parameters:
s - New text to add to the buffer
See Also:
read()

clear

public void clear()
Remove all text from the internal buffer.


2013 Sandia Corporation