CTL.Streams
Class IStream

java.lang.Object
  extended by CTL.Streams.IStream

public class IStream
extends java.lang.Object

"Intelligent" Stream: This special stream is handled just like an ObjectOutputStream, however, it saves information about the data which was written to it. Therefore, it is an easy interface to pass around data from different sources to one ObjectOutputStream and it is also capable of writing a "signature" string to the stream which can be interpreted by the readFromStream() call. This makes it possible to pass around larger amounts of arbitrary data via Object*putStreams w/o recreating the structure of the stream in code on both ends. It is also possible to query the size of the whole stream. Furthermore, the stream can write the data to other streams while keeping the data inside, which makes it ideal for debugging stream related applications.


Field Summary
private  SerialIn in
          Input stream for the internal storage
private  java.util.LinkedList<java.lang.Class> list
          LinkedList of types of the stored data
private  SerialOut out
          Output stream for the internal storage
private  int size
          Size of the stream
 
Constructor Summary
IStream()
          Create a new IStream
 
Method Summary
 void close()
          Close the stream
 void flush()
          Flush the stream
 void readFromStream(SerialIn istr)
          Read data from another IStream
private  java.lang.Object readType(java.lang.Class type)
          Read data from this stream
static java.lang.Object readType(SerialIn input, java.lang.Class typ)
          Read data from an OIStream
 void reset()
          Reset the internal storage (via Piped*Streams)
 int streamSize()
          Retrieve the size of the data this stream holds
 java.lang.String toString()
          Retrieve a string representation of this object
<T> void
write(T val)
          Write data to the stream
 void writeToIStream(SerialOut ostr)
          Write the data of this stream to another IStream while keeping it
 void writeToIStream(SerialOut ostr, boolean keep)
          Write the data of this stream to another IStream
 void writeToStream(SerialOut ostr)
          Write the data of this stream to another without keeping it
 void writeToStream(SerialOut ostr, boolean keep)
          Write the contents of this stream to another one
static
<T> void
writeType(SerialOut outp, T stuff)
          Write data to an OOStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

list

private java.util.LinkedList<java.lang.Class> list
LinkedList of types of the stored data


in

private SerialIn in
Input stream for the internal storage


out

private SerialOut out
Output stream for the internal storage


size

private int size
Size of the stream

Constructor Detail

IStream

public IStream()
        throws java.io.IOException,
               CTLException
Create a new IStream

Throws:
java.io.IOException
CTLException
Method Detail

reset

public void reset()
           throws java.io.IOException,
                  CTLException
Reset the internal storage (via Piped*Streams)

Throws:
java.io.IOException
CTLException

flush

public void flush()
           throws java.io.IOException
Flush the stream

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Close the stream

Throws:
java.io.IOException

write

public <T> void write(T val)
           throws java.io.IOException,
                  java.lang.IllegalAccessException,
                  java.lang.reflect.InvocationTargetException,
                  CTLException
Write data to the stream

Parameters:
val - Value
Throws:
java.io.IOException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
CTLException

writeType

public static <T> void writeType(SerialOut outp,
                                 T stuff)
                      throws java.lang.IllegalAccessException,
                             java.lang.reflect.InvocationTargetException
Write data to an OOStream

Parameters:
outp - Stream to write to
stuff - Data to write
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

readType

public static java.lang.Object readType(SerialIn input,
                                        java.lang.Class typ)
                                 throws java.lang.IllegalAccessException,
                                        java.lang.reflect.InvocationTargetException
Read data from an OIStream

Parameters:
input - Stream to read from
typ - Type to read
Returns:
Data read
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

readType

private java.lang.Object readType(java.lang.Class type)
                           throws java.lang.IllegalAccessException,
                                  java.lang.reflect.InvocationTargetException
Read data from this stream

Parameters:
type - Type to read
Returns:
Data read
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

toString

public java.lang.String toString()
Retrieve a string representation of this object

Overrides:
toString in class java.lang.Object
Returns:
String

writeToStream

public void writeToStream(SerialOut ostr,
                          boolean keep)
Write the contents of this stream to another one

Parameters:
ostr - Target stream
keep - Whether to keep the data in this stream

writeToStream

public void writeToStream(SerialOut ostr)
Write the data of this stream to another without keeping it

Parameters:
ostr - Target stream

writeToIStream

public void writeToIStream(SerialOut ostr)
Write the data of this stream to another IStream while keeping it

Parameters:
ostr - Target stream

writeToIStream

public void writeToIStream(SerialOut ostr,
                           boolean keep)
Write the data of this stream to another IStream

Parameters:
ostr - Target stream
keep - True if the data should be kept, false otherwise.

readFromStream

public void readFromStream(SerialIn istr)
Read data from another IStream

Parameters:
istr - Source stream

streamSize

public int streamSize()
Retrieve the size of the data this stream holds

Returns:
Size