org.subethamail.smtp.io
Class ThresholdingOutputStream
java.lang.Object
java.io.OutputStream
org.subethamail.smtp.io.ThresholdingOutputStream
- All Implemented Interfaces:
- Closeable, Flushable
- Direct Known Subclasses:
- DeferredFileOutputStream
public abstract class ThresholdingOutputStream
- extends 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
|
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 |
output
protected OutputStream output
ThresholdingOutputStream
public ThresholdingOutputStream(OutputStream base,
int thresholdBytes)
close
public void close()
throws IOException
- Specified by:
close in interface Closeable- Overrides:
close in class OutputStream
- Throws:
IOException
flush
public void flush()
throws IOException
- Specified by:
flush in interface Flushable- Overrides:
flush in class OutputStream
- Throws:
IOException
write
public void write(byte[] b,
int off,
int len)
throws IOException
- Overrides:
write in class OutputStream
- Throws:
IOException
write
public void write(byte[] b)
throws IOException
- Overrides:
write in class OutputStream
- Throws:
IOException
write
public void write(int b)
throws IOException
- Specified by:
write in class OutputStream
- Throws:
IOException
checkThreshold
protected void checkThreshold(int count)
throws IOException
- Checks whether reading count bytes would cross the limit.
- Throws:
IOException
getThreshold
public int getThreshold()
- Returns:
- the current threshold value.
thresholdReached
protected abstract void thresholdReached(int current,
int predicted)
throws 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 writtenpredicted - is the total number after the write completes
- Throws:
IOException
Copyright © 2006-2012. All Rights Reserved.