sleep.bridges.io
public class IOObject extends Object
The IOObject is the parent class for all IO Source objects that are compatible with Sleep's I/O API.
When an IOObject is created, calling openRead() with the appropriate input stream will initialize this IOObject to work with IO functions that read data. Calling openWrite() has the same effect for print functions. It is the responsibility of the IOObject child class to invoke openRead and openWrite. This is usually done in the constructor.
The pipeline for reading data looks like this:
... <- DataInputStream <- BufferedInputStream <- Original Input Stream
The pipeline for writing data is:
... -> DataOutputStream -> Original Output Stream
Field Summary | |
---|---|
protected byte[] | buffer |
protected InputStream | in |
protected OutputStream | out |
protected BufferedInputStream | reader |
protected DataInputStream | readerb |
protected InputStreamReader | readeru |
protected Thread | thread |
protected Scalar | token |
protected DataOutputStream | writerb |
protected OutputStreamWriter | writeru |
Method Summary | |
---|---|
void | close() Closes all of the reader's / writer's opened by this IOObject. |
byte[] | getBuffer(int size) |
static IOObject | getConsole(ScriptEnvironment environment) returns an IOObject that represents stdin/stdout to Sleep's I/O API. |
BufferedInputStream | getInputBuffer() Returns the ascii data reader |
InputStream | getInputStream() Returns the latest hooking point into the input stream |
OutputStream | getOutputStream() Returns the latest hooking point into the output stream |
DataInputStream | getReader() Returns the binary data reader |
Object | getSource() return the actual source of this IO for scripters to query using HOES |
Thread | getThread() returns the thread associated with this IOObject |
Scalar | getToken() returns a scalar token associated with this IOObject. |
DataOutputStream | getWriter() Returns the binary data writer |
boolean | isEOF() Returns true if the reader is closed |
void | openRead(InputStream _in) Initializes a binary reader (a DataInputStream) and a text reader (a BufferedReader) against this input stream. |
void | openWrite(OutputStream _out) Initializes a binary writer (a DataOutputStream) and a text writer (a PrintWriter) against this input stream. |
void | print(String text) Prints out a line of text with no newline character appended |
void | printLine(String text) Prints out a line of text with a newline character appended |
String | readCharacter() Reads in a character of text and returns as a string. |
String | readLine() Reads in a line of text |
void | sendEOF() Closes down the output streams effectively sending an end of file message to the reading end. |
void | setEncoding(String name) set the charset to be used for all unicode aware reads/writes from/to this stream |
void | setThread(Thread t) set the thread used for this IOObject (currently used to allow a script to wait() on the threads completion) |
void | setToken(Scalar t) sets the scalar token associated with this IOObject. |
Scalar | wait(ScriptEnvironment env, long timeout) |
&wait
function.