~ubuntu-branches/ubuntu/karmic/commons-io/karmic

« back to all changes in this revision

Viewing changes to src/java/org/apache/commons/io/output/CountingOutputStream.java

  • Committer: Bazaar Package Importer
  • Author(s): Wolfgang Baer
  • Date: 2005-10-16 13:44:21 UTC
  • Revision ID: james.westby@ubuntu.com-20051016134421-v2gfddy6iovz449t
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2001-2004 The Apache Software Foundation.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
package org.apache.commons.io.output;
 
17
 
 
18
import java.io.IOException;
 
19
import java.io.OutputStream;
 
20
 
 
21
/**
 
22
 * Used in debugging, it counts the number of bytes that pass 
 
23
 * through it.
 
24
 *
 
25
 * @author <a href="mailto:bayard@apache.org">Henri Yandell</a>
 
26
 * @version $Id: CountingOutputStream.java,v 1.5 2004/02/23 04:40:29 bayard Exp $
 
27
 */
 
28
public class CountingOutputStream extends ProxyOutputStream {
 
29
 
 
30
    private int count;
 
31
 
 
32
    /**
 
33
     * Constructs a CountingOutputStream.
 
34
     * @param out the OutputStream to write to
 
35
     */
 
36
    public CountingOutputStream( OutputStream out ) {
 
37
        super(out);
 
38
    }
 
39
 
 
40
    /** @see java.io.OutputStream#write(byte[]) */
 
41
    public void write(byte[] b) throws IOException {
 
42
        count += b.length;
 
43
        super.write(b);
 
44
    }
 
45
 
 
46
    /** @see java.io.OutputStream#write(byte[], int, int) */
 
47
    public void write(byte[] b, int off, int len) throws IOException {
 
48
        count += len;
 
49
        super.write(b, off, len);
 
50
    }
 
51
 
 
52
    /** @see java.io.OutputStream#write(int) */
 
53
    public void write(int b) throws IOException {
 
54
        count++;
 
55
        super.write(b);
 
56
    }
 
57
 
 
58
    /**
 
59
     * The number of bytes that have passed through this stream.
 
60
     * @return the number of bytes accumulated
 
61
     */
 
62
    public int getCount() {
 
63
        return this.count;
 
64
    }
 
65
 
 
66
}