EAF 7.4 Implementation

com.lutris.util
Class OutputStreamHub

java.lang.Object
  extended by java.io.OutputStream
      extended by com.lutris.util.OutputStreamHub
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class OutputStreamHub
extends java.io.OutputStream

This class implements a "hub", or redistribution center. Like a "Y" connector for garden hoses, but with an arbitrary number of outputs, not just 2.

Instances of this class maintain teir own set of OutputStreams. When you create an instance of this class, the set is empty. Writes to the hub have no effect. call add() to register OutputStreams with the hub. All OutputStream calls are routed to all the current members of the set.

Author:
Andy John
See Also:
OutputStream

Constructor Summary
OutputStreamHub()
          Create a new hub with no members.
 
Method Summary
 void add(java.io.OutputStream newMember)
          Add a new OutputStream to the set.
 void close()
          Closes the stream.
 boolean contains(java.io.OutputStream stream)
          Is the given OutputStream currently in the set?
 void flush()
          Flushes are attempted on all members.
 void remove(java.io.OutputStream member)
          Remove an OutputStream from the set.
 void write(byte[] b)
          Write an array of bytes to all the members.
 void write(byte[] b, int off, int len)
          Write part of an array of bytes to all the members.
 void write(int b)
          Write an integer to all the members.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutputStreamHub

public OutputStreamHub()
Create a new hub with no members.

Method Detail

add

public void add(java.io.OutputStream newMember)
Add a new OutputStream to the set. When write()s happen, the will be coppied to all the current members of the set.

Parameters:
newMember - The OutputStream to add to the set.
See Also:
OutputStream

remove

public void remove(java.io.OutputStream member)
Remove an OutputStream from the set.

Parameters:
member - The OutputStream to remove.
See Also:
OutputStream

contains

public boolean contains(java.io.OutputStream stream)
Is the given OutputStream currently in the set?

Parameters:
stream - The OutputStream to search for.
See Also:
OutputStream

write

public void write(int b)
           throws java.io.IOException
Write an integer to all the members. Writes are attempted on all members. The last exception thrown, if there are more than one, will be thown from this method.

Specified by:
write in class java.io.OutputStream
Parameters:
b - The int to write.
Throws:
java.io.IOException
See Also:
OutputStream

write

public void write(byte[] b)
           throws java.io.IOException
Write an array of bytes to all the members. Writes are attempted on all members. The last exception thrown, if there are more than one, will be thown from this method.

Overrides:
write in class java.io.OutputStream
Parameters:
b - The byte array to write.
Throws:
java.io.IOException
See Also:
OutputStream

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Write part of an array of bytes to all the members. Bytes b[off]..b[off+len-1] will be written. Writes are attempted on all members. The last exception thrown, if there are more than one, will be thown from this method.

Overrides:
write in class java.io.OutputStream
Parameters:
b - The byte array to write part of.
off - The offset.
len - How many bytes to write.
Throws:
java.io.IOException
See Also:
OutputStream

flush

public void flush()
           throws java.io.IOException
Flushes are attempted on all members. The last exception thrown, if there are more than one, will be thown from this method.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream

close

public void close()
           throws java.io.IOException
Closes the stream. Do not call write() after this. Calls close() on all member OutputStreams. The last exception thrown, if there are more than one, will be thown from this method.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream

EAF 7.4 Implementation