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

BytesReadResetInputStream

public class BytesReadResetInputStream extends InputStream
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
private InputStream
in
The wrapped InputStream
private Watchdog
watchdog
The Watchdog to be reset every lengthReset bytes
private int
lengthReset
The number of bytes that need to be read before the counter is reset.
int
readCounter
The number of bytes read since the counter was last reset
Constructors Summary
public BytesReadResetInputStream(InputStream in, Watchdog watchdog, int lengthReset)

param
in the InputStream to be wrapped by this stream
param
watchdog the watchdog to be reset
param
lengthReset the number of bytes to be read in between trigger resets


                                       
      
                                       
                                       
        this.in = in;
        this.watchdog = watchdog;
        this.lengthReset = lengthReset;

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

throws
IOException if an exception is encountered when closing

        in.close();
    
public intread(byte[] b, int off, int len)
Read an array of bytes from the stream

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

        int l = in.read(b, off, len);
        readCounter += l;

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

        return l;
    
public intread()
Read a byte from the stream

return
the byte read from the stream
throws
IOException if an exception is encountered when reading

        int b = in.read();
        readCounter++;

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

        return b;