1 17 18 19 package org.apache.james.util; 20 21 import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler; 22 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 26 31 public class SchedulerNotifyOutputStream extends OutputStream { 32 33 36 OutputStream out = null; 37 38 41 TimeScheduler scheduler = null; 42 43 46 String triggerName = null; 47 48 51 int lengthReset = 0; 52 53 56 int writtenCounter = 0; 57 58 public SchedulerNotifyOutputStream(OutputStream out, 59 TimeScheduler scheduler, String triggerName, int lengthReset) { 60 this.out = out; 61 this.scheduler = scheduler; 62 this.triggerName = triggerName; 63 this.lengthReset = lengthReset; 64 65 writtenCounter = 0; 66 } 67 68 77 public void write(byte[] b, int off, int len) throws IOException { 78 out.write(b, off, len); 79 writtenCounter += len; 80 81 if (writtenCounter > lengthReset) { 82 writtenCounter -= lengthReset; 83 scheduler.resetTrigger(triggerName); 84 } 85 } 86 87 94 public void write(int b) throws IOException { 95 out.write(b); 96 writtenCounter++; 97 98 if (writtenCounter > lengthReset) { 99 writtenCounter -= lengthReset; 100 scheduler.resetTrigger(triggerName); 101 } 102 } 103 104 109 public void flush() throws IOException { 110 out.flush(); 111 } 112 113 118 public void close() throws IOException { 119 out.close(); 120 } 121 } 122 | Popular Tags |