KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > util > CountingOutputStream


1 package hudson.util;
2
3 import java.io.FilterOutputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.OutputStream JavaDoc;
6
7 /**
8  * {@link FilterOutputStream} that counts the number of bytes that were written.
9  *
10  * @author Kohsuke Kawaguchi
11  */

12 public class CountingOutputStream extends FilterOutputStream JavaDoc {
13     private int count = 0;
14
15     public int getCount() {
16         return count;
17     }
18
19     public CountingOutputStream(OutputStream JavaDoc out) {
20         super(out);
21     }
22
23     public void write(int b) throws IOException JavaDoc {
24         out.write(b);
25         count++;
26     }
27
28     public void write(byte b[]) throws IOException JavaDoc {
29         out.write(b);
30         count += b.length;
31     }
32
33     public void write(byte b[], int off, int len) throws IOException JavaDoc {
34         out.write(b, off, len);
35         count += len;
36     }
37 }
38
Popular Tags