org.subethamail.smtp.server.io
Class ThresholdingOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.subethamail.smtp.server.io.ThresholdingOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
DeferredFileOutputStream

public abstract class ThresholdingOutputStream
extends java.io.OutputStream

This is an OutputStream wrapper which takes notice when a threshold (number of bytes) is about to be written. This can be used to limit output data, swap writers, etc.

Author:
Jeff Schnitzer

Field Summary
protected  java.io.OutputStream output
           
 
Constructor Summary
ThresholdingOutputStream(java.io.OutputStream base, int thresholdBytes)
           
 
Method Summary
protected  void checkThreshold(int count)
          Checks whether reading count bytes would cross the limit.
 void close()
           
 void flush()
           
 int getThreshold()
           
protected abstract  void thresholdReached(int current, int predicted)
          Called when the threshold is about to be exceeded.
 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
 

Field Detail

output

protected java.io.OutputStream output
Constructor Detail

ThresholdingOutputStream

public ThresholdingOutputStream(java.io.OutputStream base,
                                int thresholdBytes)
Method Detail

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

write

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

write

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

write

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

checkThreshold

protected void checkThreshold(int count)
                       throws java.io.IOException
Checks whether reading count bytes would cross the limit.

Throws:
java.io.IOException

getThreshold

public int getThreshold()
Returns:
the current threshold value.

thresholdReached

protected abstract void thresholdReached(int current,
                                         int predicted)
                                  throws java.io.IOException
Called when the threshold is about to be exceeded. This isn't exact; it's called whenever a write would occur that would cross the amount. Once it is called, it isn't called again.

Parameters:
current - is the current number of bytes that have been written
predicted - is the total number after the write completes
Throws:
java.io.IOException


Copyright © 2009 SubEthaSMTP. All Rights Reserved. Build version: UNVERSIONED