1 17 18 19 package org.apache.james.util.watchdog; 20 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 24 29 public class BytesWrittenResetOutputStream extends OutputStream { 30 31 34 OutputStream out = null; 35 36 39 private Watchdog watchdog; 40 41 44 int lengthReset = 0; 45 46 49 int writtenCounter = 0; 50 51 public BytesWrittenResetOutputStream(OutputStream out, 52 Watchdog watchdog, 53 int lengthReset) { 54 this.out = out; 55 this.watchdog = watchdog; 56 this.lengthReset = lengthReset; 57 58 writtenCounter = 0; 59 } 60 61 70 public void write(byte[] b, int off, int len) throws IOException { 71 out.write(b, off, len); 72 writtenCounter += len; 73 74 if (writtenCounter > lengthReset) { 75 writtenCounter = 0; 76 watchdog.reset(); 77 } 78 } 79 80 87 public void write(int b) throws IOException { 88 out.write(b); 89 writtenCounter++; 90 91 if (writtenCounter > lengthReset) { 92 writtenCounter = 0; 93 watchdog.reset(); 94 } 95 } 96 97 102 public void flush() throws IOException { 103 out.flush(); 104 } 105 106 111 public void close() throws IOException { 112 out.close(); 113 } 114 } 115 | Popular Tags |