KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > io > CountedOutputStream


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.io;
9
10 import java.io.*;
11
12 /**
13  * <tt>OutputStream</tt> which counts the number of bytes written.
14  *
15  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
16  * @version $Revision: 1.4 $ $Date: 2004/12/28 13:04:31 $
17  */

18 public class CountedOutputStream extends FilterOutputStream {
19
20     private int bytesWritten = 0;
21
22     /**
23      * Constructor.
24      *
25      * @param out the output stream.
26      */

27     public CountedOutputStream(OutputStream out) {
28         super(out);
29     }
30
31     public void write(int b) throws IOException {
32         out.write(b);
33         bytesWritten++;
34     }
35
36     /**
37      * Get the number of bytes written.
38      *
39      * @return the number of bytes
40      */

41     public int getBytesWritten() {
42         return bytesWritten;
43     }
44 }
45
Popular Tags