edu.nmu.io
Class DelegatedOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--edu.nmu.io.DelegatedOutputStream

public class DelegatedOutputStream
extends java.io.OutputStream

Writes output to another OutputStream

By using delegation as a level of abstraction, applications can change the destination of output without needing to reference a new OutputStream. This is especially useful for changing the source of input for final references such as System.out

It is important to note that this class is not thread safe. A call to the delegated OutputStream could forseeably hang while another Thread calls setStream(OutputStream)

Since:
jdk1.4
Version:
1.0, 01/24/2003
Author:
Matt Murphy

Constructor Summary
DelegatedOutputStream(java.io.OutputStream out)
          Creates a new DelegatedOutputStream from the specified OutputStream
 
Method Summary
 void close()
           
 void flush()
           
 java.io.OutputStream getStream()
          Gets the OutputStream used for delegation
 void setStream(java.io.OutputStream out)
          Sets a new OutputStream to be used for delegation
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatedOutputStream

public DelegatedOutputStream(java.io.OutputStream out)
Creates a new DelegatedOutputStream from the specified OutputStream

Parameters:
out - the OutputStream to which calls should be delegated
Method Detail

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Overrides:
flush in class java.io.OutputStream
java.io.IOException

close

public void close()
           throws java.io.IOException
Overrides:
close in class java.io.OutputStream
java.io.IOException

getStream

public java.io.OutputStream getStream()
Gets the OutputStream used for delegation

Returns:
the OutputStream

setStream

public void setStream(java.io.OutputStream out)
Sets a new OutputStream to be used for delegation

Parameters:
out - the OutputStream to which calls should be delegated