1 package org.apache.jcs.admin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.io.OutputStream;
24
25 /***
26 * Keeps track of the number of bytes written to it, but doesn't write them anywhere.
27 */
28 public class CountingOnlyOutputStream
29 extends OutputStream
30 {
31 /*** number of bytes passed through */
32 private int count;
33
34 /***
35 * count as we write.
36 * <p>
37 * @param b
38 * @throws IOException
39 */
40 public void write( byte[] b )
41 throws IOException
42 {
43 this.count += b.length;
44 }
45
46 /***
47 * count as we write.
48 * <p>
49 * @param b
50 * @param off
51 * @param len
52 * @throws IOException
53 */
54 public void write( byte[] b, int off, int len )
55 throws IOException
56 {
57 this.count += len;
58 }
59
60 /***
61 * count as we write.
62 * <p>
63 * @param b
64 * @throws IOException
65 */
66 public void write( int b )
67 throws IOException
68 {
69 this.count++;
70 }
71
72 /***
73 * The number of bytes that have passed through this stream.
74 * <p>
75 * @return int
76 */
77 public int getCount()
78 {
79 return this.count;
80 }
81 }