Debian Codegraph @

src/main/java/org/freehep/util/io/CountedByteOutputStream.java

raw
1 // Copyright 2001, FreeHEP.
2 package org.freehep.util.io;
3
4 import java.io.FilterOutputStream;
5 import java.io.IOException;
6 import java.io.OutputStream;
7
8 /**
9 * The CountedByteOutputStream counts the number of bytes written.
10 *
11 * @author Mark Donszelmann
12 * @version $Id: CountedByteOutputStream.java 8584 2006-08-10 23:06:37Z duns $
13 */
14 public class CountedByteOutputStream extends FilterOutputStream {
15
16 private int count;
17
18 /**
19 * Creates a Counted Bytes output stream from the given stream.
20 *
21 * @param out stream to write to
22 */
23 public CountedByteOutputStream(OutputStream out) {
24 super(out);
25 count = 0;
26 }
27
28 public void write(int b) throws IOException {
29 out.write(b);
30 count++;
31 }
32
33 public void write(byte[] b) throws IOException {
34 out.write(b);
35 count += b.length;
36 }
37
38 public void write(byte[] b, int offset, int len) throws IOException {
39 out.write(b, offset, len);
40 count += len;
41 }
42
43 /**
44 * @return number of bytes written.
45 */
46 public int getCount() {
47 return count;
48 }
49 }