Package sleep.bridges.io
Class IOObject
- java.lang.Object
-
- sleep.bridges.io.IOObject
-
public class IOObject extends java.lang.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
Fields Modifier and Type Field Description protected java.io.InputStream
in
protected java.io.OutputStream
out
protected java.io.BufferedInputStream
reader
protected java.io.DataInputStream
readerb
protected java.io.InputStreamReader
readeru
protected java.lang.Thread
thread
protected Scalar
token
protected java.io.DataOutputStream
writerb
protected java.io.OutputStreamWriter
writeru
-
Constructor Summary
Constructors Constructor Description IOObject()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes all of the reader's / writer's opened by this IOObject.static IOObject
getConsole(ScriptEnvironment environment)
returns an IOObject that represents stdin/stdout to Sleep's I/O API.java.io.BufferedInputStream
getInputBuffer()
Returns the ascii data readerjava.io.InputStream
getInputStream()
Returns the latest hooking point into the input streamjava.io.OutputStream
getOutputStream()
Returns the latest hooking point into the output streamjava.io.DataInputStream
getReader()
Returns the binary data readerjava.lang.Object
getSource()
return the actual source of this IO for scripters to query using HOESjava.lang.Thread
getThread()
returns the thread associated with this IOObjectScalar
getToken()
returns a scalar token associated with this IOObject.java.io.DataOutputStream
getWriter()
Returns the binary data writerboolean
isEOF()
Returns true if the reader is closedvoid
openRead(java.io.InputStream _in)
Initializes a binary reader (a DataInputStream) and a text reader (a BufferedReader) against this input stream.void
openWrite(java.io.OutputStream _out)
Initializes a binary writer (a DataOutputStream) and a text writer (a PrintWriter) against this input stream.void
print(java.lang.String text)
Prints out a line of text with no newline character appendedvoid
printLine(java.lang.String text)
Prints out a line of text with a newline character appendedjava.lang.String
readCharacter()
Reads in a character of text and returns as a string.java.lang.String
readLine()
Reads in a line of textvoid
sendEOF()
Closes down the output streams effectively sending an end of file message to the reading end.static void
setConsole(ScriptEnvironment environment, IOObject object)
sets the stdin/stdout for this script environment.void
setEncoding(java.lang.String name)
set the charset to be used for all unicode aware reads/writes from/to this streamvoid
setThread(java.lang.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)
-
-
-
Field Detail
-
readeru
protected java.io.InputStreamReader readeru
-
readerb
protected java.io.DataInputStream readerb
-
reader
protected java.io.BufferedInputStream reader
-
in
protected java.io.InputStream in
-
writeru
protected java.io.OutputStreamWriter writeru
-
writerb
protected java.io.DataOutputStream writerb
-
out
protected java.io.OutputStream out
-
thread
protected java.lang.Thread thread
-
token
protected Scalar token
-
-
Method Detail
-
getSource
public java.lang.Object getSource()
return the actual source of this IO for scripters to query using HOES
-
setEncoding
public void setEncoding(java.lang.String name) throws java.io.UnsupportedEncodingException
set the charset to be used for all unicode aware reads/writes from/to this stream- Throws:
java.io.UnsupportedEncodingException
-
setThread
public void setThread(java.lang.Thread t)
set the thread used for this IOObject (currently used to allow a script to wait() on the threads completion)
-
getThread
public java.lang.Thread getThread()
returns the thread associated with this IOObject
-
wait
public Scalar wait(ScriptEnvironment env, long timeout)
-
getToken
public Scalar getToken()
returns a scalar token associated with this IOObject. Will return the empty scalar if the token is null. The token is essentially the stored return value of an executing thread.
-
setToken
public void setToken(Scalar t)
sets the scalar token associated with this IOObject. Any ScriptInstance object calls setToken on it's parent IOObject. This method is called when the script is finished running and has a return value waiting. This value can be retrieved in Sleep with the&wait
function.
-
setConsole
public static void setConsole(ScriptEnvironment environment, IOObject object)
sets the stdin/stdout for this script environment. This value is placed into the script metadata with the %console% key
-
getConsole
public static IOObject getConsole(ScriptEnvironment environment)
returns an IOObject that represents stdin/stdout to Sleep's I/O API.
-
getInputStream
public java.io.InputStream getInputStream()
Returns the latest hooking point into the input stream
-
getOutputStream
public java.io.OutputStream getOutputStream()
Returns the latest hooking point into the output stream
-
openRead
public void openRead(java.io.InputStream _in)
Initializes a binary reader (a DataInputStream) and a text reader (a BufferedReader) against this input stream. Calling this effectively makes this IOObject useable with Sleep's IO read* functions.
-
openWrite
public void openWrite(java.io.OutputStream _out)
Initializes a binary writer (a DataOutputStream) and a text writer (a PrintWriter) against this input stream. Calling this effectively makes this IOObject useable with Sleep's IO print* functions.
-
close
public void close()
Closes all of the reader's / writer's opened by this IOObject. If the IO Source object opens any streams, this method should be overriden to close those streams when requested. Calling super.close() is highly recommended as well.
-
readLine
public java.lang.String readLine()
Reads in a line of text
-
readCharacter
public java.lang.String readCharacter()
Reads in a character of text and returns as a string.
-
isEOF
public boolean isEOF()
Returns true if the reader is closed
-
sendEOF
public void sendEOF()
Closes down the output streams effectively sending an end of file message to the reading end.
-
getInputBuffer
public java.io.BufferedInputStream getInputBuffer()
Returns the ascii data reader
-
getReader
public java.io.DataInputStream getReader()
Returns the binary data reader
-
getWriter
public java.io.DataOutputStream getWriter()
Returns the binary data writer
-
printLine
public void printLine(java.lang.String text)
Prints out a line of text with a newline character appended
-
print
public void print(java.lang.String text)
Prints out a line of text with no newline character appended
-
-