2020import java .io .OutputStream ;
2121
2222/**
23- * Used in debugging, it counts the number of bytes that pass
24- * through it.
23+ * A decorating output stream that counts the number of bytes that have passed
24+ * through the stream so far.
25+ * <p>
26+ * A typical use case would be during debugging, to ensure that data is being
27+ * written as expected.
2528 *
26- * @author <a href="mailto:bayard@apache.org"> Henri Yandell</a>
29+ * @author Henri Yandell
2730 * @version $Id$
2831 */
2932public class CountingOutputStream extends ProxyOutputStream {
3033
34+ /** The count of bytes that have passed. */
3135 private long count ;
3236
3337 /**
34- * Constructs a CountingOutputStream.
35- * @param out the OutputStream to write to
38+ * Constructs a new CountingOutputStream.
39+ *
40+ * @param out the OutputStream to write to
3641 */
3742 public CountingOutputStream ( OutputStream out ) {
3843 super (out );
3944 }
4045
41- /** @see java.io.OutputStream#write(byte[]) */
46+ //-----------------------------------------------------------------------
47+ /**
48+ * Writes the contents of the specified byte array to this output stream
49+ * keeping count of the number of bytes written.
50+ *
51+ * @param b the bytes to write, not null
52+ * @throws IOException if an I/O error occurs
53+ * @see java.io.OutputStream#write(byte[])
54+ */
4255 public void write (byte [] b ) throws IOException {
4356 count += b .length ;
4457 super .write (b );
4558 }
4659
47- /** @see java.io.OutputStream#write(byte[], int, int) */
60+ /**
61+ * Writes a portion of the specified byte array to this output stream
62+ * keeping count of the number of bytes written.
63+ *
64+ * @param b the bytes to write, not null
65+ * @param off the start offset in the buffer
66+ * @param len the maximum number of bytes to write
67+ * @throws IOException if an I/O error occurs
68+ * @see java.io.OutputStream#write(byte[], int, int)
69+ */
4870 public void write (byte [] b , int off , int len ) throws IOException {
4971 count += len ;
5072 super .write (b , off , len );
5173 }
5274
53- /** @see java.io.OutputStream#write(int) */
75+ /**
76+ * Writes a single byte to the output stream adding to the count of the
77+ * number of bytes written.
78+ *
79+ * @param b the byte to write
80+ * @see java.io.OutputStream#write(int)
81+ */
5482 public void write (int b ) throws IOException {
5583 count ++;
5684 super .write (b );
5785 }
5886
87+ //-----------------------------------------------------------------------
5988 /**
6089 * The number of bytes that have passed through this stream.
6190 * <p>
@@ -67,7 +96,7 @@ public void write(int b) throws IOException {
6796 * @deprecated use <code>getByteCount()</code> - see issue IO-84
6897 */
6998 public int getCount () {
70- return (int )getByteCount ();
99+ return (int ) getByteCount ();
71100 }
72101
73102 /**
@@ -81,36 +110,37 @@ public int getCount() {
81110 * @deprecated use <code>resetByteCount()</code> - see issue IO-84
82111 */
83112 public synchronized int resetCount () {
84- return (int )resetByteCount ();
113+ return (int ) resetByteCount ();
85114 }
86115
87116 /**
88117 * The number of bytes that have passed through this stream.
89118 * <p>
90- * <strong>N.B.</strong> This method was introduced as an
91- * alternative for the <code>getCount()</code> method
92- * because that method returns an integer which will result
93- * in incorrect count for files over 2GB being returned.
119+ * NOTE: This method is a replacement for <code>getCount()</code>.
120+ * It was added because that method returns an integer which will
121+ * result in incorrect count for files over 2GB.
94122 *
95123 * @return the number of bytes accumulated
124+ * @since Commons IO 1.3
96125 */
97126 public long getByteCount () {
98127 return this .count ;
99128 }
100129
101130 /**
102- * Set the count back to 0.
131+ * Set the byte count back to 0.
103132 * <p>
104- * <strong>N.B.</strong> This method was introduced as an
105- * alternative for the <code>resetCount()</code> method
106- * because that method returns an integer which will result
107- * in incorrect count for files over 2GB being returned.
133+ * NOTE: This method is a replacement for <code>resetCount()</code>.
134+ * It was added because that method returns an integer which will
135+ * result in incorrect count for files over 2GB.
108136 *
109- * @return the count previous to resetting.
137+ * @return the count previous to resetting
138+ * @since Commons IO 1.3
110139 */
111140 public synchronized long resetByteCount () {
112141 long tmp = this .count ;
113142 this .count = 0 ;
114143 return tmp ;
115144 }
145+
116146}
0 commit comments