LiveGraph
data visualisation and analysis framework

org.LiveGraph.dataFile.write
Class PipedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.LiveGraph.dataFile.write.PipedOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class PipedOutputStream
extends java.io.OutputStream


Field Summary
private  PipedInputStream sink
           
 
Constructor Summary
PipedOutputStream()
          Creates a piped output stream that is not yet connected to a piped input stream.
PipedOutputStream(PipedInputStream snk)
          Creates a piped output stream connected to the specified piped input stream.
 
Method Summary
 void close()
          Closes this piped output stream and releases any system resources associated with this stream.
 void connect(PipedInputStream sink)
          Connects this piped output stream to a receiver.
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this piped output stream.
 void write(int b)
          Writes the specified byte to the piped output stream.
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sink

private PipedInputStream sink
Constructor Detail

PipedOutputStream

public PipedOutputStream()
Creates a piped output stream that is not yet connected to a piped input stream. It must be connected to a piped input stream, either by the receiver or the sender, before being used.


PipedOutputStream

public PipedOutputStream(PipedInputStream snk)
                  throws java.io.IOException
Creates a piped output stream connected to the specified piped input stream. Data bytes written to this stream will then be available as input from snk.

Parameters:
snk - The piped input stream to connect to.
Throws:
java.io.IOException - if an I/O error occurs.
Method Detail

connect

public void connect(PipedInputStream sink)
             throws java.io.IOException
Connects this piped output stream to a receiver. If this object is already connected to some other piped input stream, an IOException is thrown.
If snk is an unconnected piped input stream and src is an unconnected piped output stream, they may be connected by either the call:
src.connect(snk)

or the call:
snk.connect(src)

The two calls have the same effect.

Parameters:
sink - the piped input stream to connect to.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to the piped output stream.
Implements the write method of OutputStream. This method blocks for a while to wait until the byte is written to the output stream, but quits the block and throws a PipedInputStream.PipeFullException if the data cannot be written within a certain time period.

Specified by:
write in class java.io.OutputStream
Parameters:
b - the byte to be written.
Throws:
java.io.IOException - if the pipe is broken, unconnected, closed, or if an I/O error occurs; specifically, a {link PipeFullException, if the receiving buffer is full and waiting times out.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this piped output stream. This method blocks for a while to wait until all the bytes are written to the output stream, but quits the block and throws a PipedInputStream.PipeFullException if the data cannot be written within a certain time period.

Overrides:
write in class java.io.OutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
java.io.IOException - if the pipe is broken, unconnected, closed, or if an I/O error occurs; specifically, a {link PipeFullException, if the receiving buffer is full and waiting times out.

flush

public void flush()
           throws java.io.IOException
Flushes this output stream and forces any buffered output bytes to be written out. This will notify any readers that bytes are waiting in the pipe.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - if an I/O error occurs.

close

public void close()
           throws java.io.IOException
Closes this piped output stream and releases any system resources associated with this stream. This stream may no longer be used for writing bytes.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - if an I/O error occurs.

LiveGraph
data visualisation and analysis framework