Annotation of java/classes/org/w3c/util/CountOutputStream.java, revision 1.4

1.1       abaird      1: // CountOutputStream.java
1.4     ! ylafon      2: // $Id: CountOutputStream.java,v 1.3 2000/08/16 21:37:57 ylafon Exp $
1.1       abaird      3: // (c) COPYRIGHT MIT and INRIA, 1996.
                      4: // Please first read the full copyright statement in file COPYRIGHT.html
                      5: 
1.2       bmahe       6: package org.w3c.util;
1.1       abaird      7: 
                      8: import java.io.OutputStream;
                      9: 
                     10: /**
                     11:  * This class can be used to count number of bytes emitted to a stream.
                     12:  * The stream will actually throw the data away. It's main function is
                     13:  * to count the number of bytes emitted to a stream before actually emitting
                     14:  * the bytes (that's not really efficient, but works enough).
                     15:  */
                     16: 
                     17: public class CountOutputStream extends OutputStream {
                     18:     protected int count = 0;
1.3       ylafon     19: 
1.1       abaird     20:     /**
                     21:      * Get the current number of bytes emitted to that stream.
                     22:      * @return The current count value.
                     23:      */
                     24: 
                     25:     public int getCount() {
                     26:        return count;
                     27:     }
                     28: 
                     29:     /**
                     30:      * Close that count stream.
                     31:      */
                     32: 
                     33:     public void close() {
                     34:     }
                     35: 
                     36:     /**
                     37:      * Flush that count stream.
                     38:      */
                     39: 
                     40:     public void flush() {
                     41:     }
                     42: 
                     43:     /**
                     44:      * Write an array of bytes to that stream.
                     45:      */
                     46: 
                     47:     public void write(byte b[]) {
                     48:        count += b.length;
                     49:     }
                     50: 
                     51:     /**
                     52:      * Write part of an array of bytes to that stream.
                     53:      */
                     54: 
                     55:     public void write(byte b[], int off, int len) {
                     56:        count += len;
                     57:     }
                     58: 
                     59:     /**
                     60:      * Write a single byte to that stream.
                     61:      */
                     62: 
                     63:     public void write(int b) {
                     64:        count++;
                     65:     }
                     66: 
                     67:     /**
                     68:      * Create a new instance of that class.
                     69:      */
                     70: 
                     71:     public CountOutputStream() {
                     72:        this.count = 0;
                     73:     }
                     74: 
                     75: }

Webmaster