01: // CountOutputStream.java
02: // $Id: CountOutputStream.java,v 1.3 2000/08/16 21:37:57 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.util;
07:
08: import java.io.OutputStream;
09:
10: /**
11: * This class can be used to count number of bytes emitted to a stream.
12: * The stream will actually throw the data away. It's main function is
13: * to count the number of bytes emitted to a stream before actually emitting
14: * the bytes (that's not really efficient, but works enough).
15: */
16:
17: public class CountOutputStream extends OutputStream {
18: protected int count = 0;
19:
20: /**
21: * Get the current number of bytes emitted to that stream.
22: * @return The current count value.
23: */
24:
25: public int getCount() {
26: return count;
27: }
28:
29: /**
30: * Close that count stream.
31: */
32:
33: public void close() {
34: return;
35: }
36:
37: /**
38: * Flush that count stream.
39: */
40:
41: public void flush() {
42: return;
43: }
44:
45: /**
46: * Write an array of bytes to that stream.
47: */
48:
49: public void write(byte b[]) {
50: count += b.length;
51: }
52:
53: /**
54: * Write part of an array of bytes to that stream.
55: */
56:
57: public void write(byte b[], int off, int len) {
58: count += len;
59: }
60:
61: /**
62: * Write a single byte to that stream.
63: */
64:
65: public void write(int b) {
66: count++;
67: }
68:
69: /**
70: * Create a new instance of that class.
71: */
72:
73: public CountOutputStream() {
74: this .count = 0;
75: }
76:
77: }
|