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.InputStream ; 25 26 31 public class SchedulerNotifyInputStream extends InputStream { 32 33 36 InputStream in = null; 37 38 41 TimeScheduler scheduler = null; 42 43 46 String triggerName = null; 47 48 51 int lengthReset = 0; 52 53 56 int readCounter = 0; 57 58 64 public SchedulerNotifyInputStream(InputStream in, 65 TimeScheduler scheduler, String triggerName, int lengthReset) { 66 this.in = in; 67 this.scheduler = scheduler; 68 this.triggerName = triggerName; 69 this.lengthReset = lengthReset; 70 71 readCounter = 0; 72 } 73 74 85 public int read(byte[] b, int off, int len) throws IOException { 86 int l = in.read(b, off, len); 87 readCounter += l; 88 89 if (readCounter > lengthReset) { 90 readCounter -= lengthReset; 91 scheduler.resetTrigger(triggerName); 92 } 93 94 return l; 95 } 96 97 103 public int read() throws IOException { 104 int b = in.read(); 105 readCounter++; 106 107 if (readCounter > lengthReset) { 108 readCounter -= lengthReset; 109 scheduler.resetTrigger(triggerName); 110 } 111 112 return b; 113 } 114 115 120 public void close() throws IOException { 121 in.close(); 122 } 123 } 124 | Popular Tags |