1 17 18 19 package org.apache.james.util.watchdog; 20 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 24 29 public class BytesReadResetInputStream extends InputStream { 30 31 34 private InputStream in = null; 35 36 39 private Watchdog watchdog; 40 41 44 private int lengthReset = 0; 45 46 49 int readCounter = 0; 50 51 56 public BytesReadResetInputStream(InputStream in, 57 Watchdog watchdog, 58 int lengthReset) { 59 this.in = in; 60 this.watchdog = watchdog; 61 this.lengthReset = lengthReset; 62 63 readCounter = 0; 64 } 65 66 77 public int read(byte[] b, int off, int len) throws IOException { 78 int l = in.read(b, off, len); 79 readCounter += l; 80 81 if (readCounter > lengthReset) { 82 readCounter = 0; 83 watchdog.reset(); 84 } 85 86 return l; 87 } 88 89 95 public int read() throws IOException { 96 int b = in.read(); 97 readCounter++; 98 99 if (readCounter > lengthReset) { 100 readCounter = 0; 101 watchdog.reset(); 102 } 103 104 return b; 105 } 106 107 112 public void close() throws IOException { 113 in.close(); 114 } 115 } 116 | Popular Tags |