FileDocCategorySizeDatePackage
BytesWrittenResetOutputStream.javaAPI DocApache James 2.3.13681Fri Jan 12 12:56:34 GMT 2007org.apache.james.util.watchdog

BytesWrittenResetOutputStream

public class BytesWrittenResetOutputStream extends OutputStream
This will reset the Watchdog each time a certain amount of data has been transferred. This allows us to keep the timeout settings low, while not timing out during large data transfers.

Fields Summary
OutputStream
out
The output stream wrapped by this method
private Watchdog
watchdog
The Watchdog to be reset every lengthReset bytes
int
lengthReset
The number of bytes that need to be written before the counter is reset.
int
writtenCounter
The number of bytes written since the counter was last reset
Constructors Summary
public BytesWrittenResetOutputStream(OutputStream out, Watchdog watchdog, int lengthReset)


      
                                          
                                           
        this.out = out;
        this.watchdog = watchdog;
        this.lengthReset = lengthReset;

        writtenCounter = 0;
    
Methods Summary
public voidclose()
Close the stream

throws
IOException if an exception is encountered when closing

        out.close();
    
public voidflush()
Flush the stream

throws
IOException if an exception is encountered when flushing

        out.flush();
    
public voidwrite(byte[] b, int off, int len)
Write an array of bytes to the stream

param
b the array of bytes to write to the stream
param
off the index in the array where we start writing
param
len the number of bytes of the array to write
throws
IOException if an exception is encountered when writing

        out.write(b, off, len);
        writtenCounter += len;

        if (writtenCounter > lengthReset) {
            writtenCounter = 0;
            watchdog.reset();
        }
    
public voidwrite(int b)
Write a byte to the stream

param
b the byte to write to the stream
throws
IOException if an exception is encountered when writing

        out.write(b);
        writtenCounter++;

        if (writtenCounter > lengthReset) {
            writtenCounter = 0;
            watchdog.reset();
        }