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

SchedulerNotifyOutputStream

public class SchedulerNotifyOutputStream extends OutputStream
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
OutputStream
out
The output stream wrapped by this method
org.apache.avalon.cornerstone.services.scheduler.TimeScheduler
scheduler
The scheduler used by this class to timeout
String
triggerName
The name of the trigger
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 SchedulerNotifyOutputStream(OutputStream out, org.apache.avalon.cornerstone.services.scheduler.TimeScheduler scheduler, String triggerName, int lengthReset)


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