Skip to content

Commit d25ed53

Browse files
author
Stephen Colebourne
committed
Javadoc, checkstyle and since tags
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@462807 13f79535-47bb-0310-9956-ffa450edef68
1 parent b793c19 commit d25ed53

2 files changed

Lines changed: 87 additions & 32 deletions

File tree

src/java/org/apache/commons/io/input/CountingInputStream.java

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
import java.io.InputStream;
2121

2222
/**
23-
* A decorating input stream that counts the number of bytes that
24-
* have passed through so far.
23+
* A decorating input 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+
* read as expected.
2528
*
2629
* @author Henri Yandell
2730
* @author Marcelo Liberato
@@ -34,15 +37,21 @@ public class CountingInputStream extends ProxyInputStream {
3437

3538
/**
3639
* Constructs a new CountingInputStream.
37-
* @param in InputStream to delegate to
40+
*
41+
* @param in the InputStream to delegate to
3842
*/
3943
public CountingInputStream(InputStream in) {
4044
super(in);
4145
}
4246

47+
//-----------------------------------------------------------------------
4348
/**
44-
* Increases the count by super.read(b)'s return count
45-
*
49+
* Reads a number of bytes into the byte array, keeping count of the
50+
* number read.
51+
*
52+
* @param b the buffer into which the data is read, not null
53+
* @return the total number of bytes read into the buffer, -1 if end of stream
54+
* @throws IOException if an I/O error occurs
4655
* @see java.io.InputStream#read(byte[])
4756
*/
4857
public int read(byte[] b) throws IOException {
@@ -52,8 +61,14 @@ public int read(byte[] b) throws IOException {
5261
}
5362

5463
/**
55-
* Increases the count by super.read(b, off, len)'s return count
64+
* Reads a number of bytes into the byte array at a specific offset,
65+
* keeping count of the number read.
5666
*
67+
* @param b the buffer into which the data is read, not null
68+
* @param off the start offset in the buffer
69+
* @param len the maximum number of bytes to read
70+
* @return the total number of bytes read into the buffer, -1 if end of stream
71+
* @throws IOException if an I/O error occurs
5772
* @see java.io.InputStream#read(byte[], int, int)
5873
*/
5974
public int read(byte[] b, int off, int len) throws IOException {
@@ -63,19 +78,26 @@ public int read(byte[] b, int off, int len) throws IOException {
6378
}
6479

6580
/**
66-
* Increases the count by 1 if a byte is successfully read.
81+
* Reads the next byte of data adding to the count of bytes received
82+
* if a byte is successfully read.
6783
*
84+
* @return the byte read, -1 if end of stream
85+
* @throws IOException if an I/O error occurs
6886
* @see java.io.InputStream#read()
6987
*/
7088
public int read() throws IOException {
7189
int found = super.read();
7290
this.count += (found >= 0) ? 1 : 0;
7391
return found;
7492
}
75-
93+
7694
/**
77-
* Increases the count by the number of skipped bytes.
78-
*
95+
* Skips the stream over the specified number of bytes, adding the skipped
96+
* amount to the count.
97+
*
98+
* @param length the number of bytes to skip
99+
* @return the actual number of bytes skipped
100+
* @throws IOException if an I/O error occurs
79101
* @see java.io.InputStream#skip(long)
80102
*/
81103
public long skip(final long length) throws IOException {
@@ -84,6 +106,7 @@ public long skip(final long length) throws IOException {
84106
return skip;
85107
}
86108

109+
//-----------------------------------------------------------------------
87110
/**
88111
* The number of bytes that have passed through this stream.
89112
* <p>
@@ -120,19 +143,21 @@ public synchronized int resetCount() {
120143
* result in incorrect count for files over 2GB.
121144
*
122145
* @return the number of bytes accumulated
146+
* @since Commons IO 1.3
123147
*/
124148
public long getByteCount() {
125149
return this.count;
126150
}
127151

128152
/**
129-
* Set the count back to 0.
153+
* Set the byte count back to 0.
130154
* <p>
131155
* NOTE: This method is a replacement for <code>resetCount()</code>
132156
* and was added because that method returns an integer which will
133157
* result in incorrect count for files over 2GB.
134158
*
135-
* @return the count previous to resetting.
159+
* @return the count previous to resetting
160+
* @since Commons IO 1.3
136161
*/
137162
public synchronized long resetByteCount() {
138163
long tmp = this.count;

src/java/org/apache/commons/io/output/CountingOutputStream.java

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,71 @@
2020
import 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
*/
2932
public 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

Comments
 (0)