001    package railo.commons.io;
002    
003    import java.io.IOException;
004    import java.io.OutputStream;
005    
006    /**
007     * 
008     */
009    public final class CountingOutputStream extends OutputStream {
010        
011        private final OutputStream os;
012        private int count=0;
013    
014        /**
015         * @param os
016         */
017        public CountingOutputStream(OutputStream os) {
018            this.os=os;
019        }
020        
021        /**
022         * @see java.io.OutputStream#close()
023         */
024        public void close() throws IOException {
025            os.close();
026        }
027    
028        /**
029         * @see java.io.OutputStream#flush()
030         */
031        public void flush() throws IOException {
032            os.flush();
033        }
034    
035        /**
036         * @see java.io.OutputStream#write(byte[], int, int)
037         */
038        public void write(byte[] b, int off, int len) throws IOException {
039            count+=len;
040            os.write(b, off, len);
041        }
042    
043        /**
044         * @see java.io.OutputStream#write(byte[])
045         */
046        public void write(byte[] b) throws IOException {
047            count+=b.length;
048            os.write(b);
049        }
050    
051        /**
052         * @see java.io.OutputStream#write(int)
053         */
054        public void write(int b) throws IOException {
055            count++;
056            os.write(b);
057        }
058    
059        /**
060         * @return Returns the count.
061         */
062        public int getCount() {
063            return count;
064        }
065    
066    }