FileDocCategorySizeDatePackage
SchedulerNotifyInputStream.javaAPI DocApache James 2.3.14061Fri Jan 12 12:56:34 GMT 2007org.apache.james.util

SchedulerNotifyInputStream

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

Fields Summary
InputStream
in
The wrapped InputStream
org.apache.avalon.cornerstone.services.scheduler.TimeScheduler
scheduler
The scheduler managing the trigger to be reset by this stream
String
triggerName
The name of the trigger
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 SchedulerNotifyInputStream(InputStream in, org.apache.avalon.cornerstone.services.scheduler.TimeScheduler scheduler, String triggerName, int lengthReset)

param
in the InputStream to be wrapped by this stream
param
scheduler the TimeScheduler managing the trigger to be reset by this stream
param
triggerName the name of the particular trigger to be reset by this stream
param
lengthReset the number of bytes to be read in between trigger resets


                                                           
      
                  
        this.in = in;
        this.scheduler = scheduler;
        this.triggerName = triggerName;
        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 -= lengthReset;
            scheduler.resetTrigger(triggerName);
        }

        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 -= lengthReset;
            scheduler.resetTrigger(triggerName);
        }

        return b;