nu.dll.io
Class SpyOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--nu.dll.io.SpyOutputStream

public class SpyOutputStream
extends java.io.FilterOutputStream

The SpyInputStream and SpyOutputStream classes are Input- and OutputStream filters that enabled "spying" on input and output streams by attaching OutputStream objects as "spies", to which, whenever data is written to or read from the underlying stream, exactly the same data is written to all currently attached spy output streams.

The eavesdroppers can be attached and removed through the addSpy() and removeSpy() methods, or by the two-args constructor which takes an output stream to dump the data to as the second argument. An arbitrary number of spy streams can be attached, but it inevitably affects the performance, since read() and write() methods blocks until all data has been written to all eavesdropping output streams.

The data is written to the attached eavesdroppers using the same methods by which the SpyStream object is called, or, in the case of SpyInputStream, each read() call triggers it's eavesdropper's corresponding write() call.

This class also contains the functionality to print out debug information every n bytes, where n is set by the setStatusLimit(int) method (defaults to 100 bytes). It also keeps track of the total number of bytes passed through the underlying stream. This is useful to debug the efficiency of bulk write() calls, for example.


Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
SpyOutputStream(java.io.OutputStream out)
           
SpyOutputStream(java.io.OutputStream out1, java.io.OutputStream out2)
           
 
Method Summary
 void addSpy(java.io.OutputStream spy)
           
 void close()
           
 void finalize()
           
 long getCount()
           
 long getCountOff()
           
 void removeSpy(java.io.OutputStream spy)
           
 void setAutoStatus(boolean B)
           
 void setStatusLimit(long I)
          Sets the treshold of the number of bytes to pass before automatically writing debug info to stdout.
protected static void trace(java.lang.String s)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeStatus()
           
 void writeStatusMaybe()
           
 
Methods inherited from class java.io.FilterOutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpyOutputStream

public SpyOutputStream(java.io.OutputStream out)

SpyOutputStream

public SpyOutputStream(java.io.OutputStream out1,
                       java.io.OutputStream out2)
Method Detail

addSpy

public void addSpy(java.io.OutputStream spy)

removeSpy

public void removeSpy(java.io.OutputStream spy)

setAutoStatus

public void setAutoStatus(boolean B)

write

public void write(int b)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream

write

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

writeStatusMaybe

public void writeStatusMaybe()

setStatusLimit

public void setStatusLimit(long I)
Sets the treshold of the number of bytes to pass before automatically writing debug info to stdout.
Parameters:
I - the number of bytes
See Also:
setAutoStatus(boolean)

writeStatus

public void writeStatus()

getCount

public long getCount()

getCountOff

public long getCountOff()

close

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

trace

protected static void trace(java.lang.String s)

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object