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        @Override
022        public void close() throws IOException {
023            os.close();
024        }
025    
026        @Override
027        public void flush() throws IOException {
028            os.flush();
029        }
030    
031        @Override
032        public void write(byte[] b, int off, int len) throws IOException {
033            count+=len;
034            os.write(b, off, len);
035        }
036    
037        @Override
038        public void write(byte[] b) throws IOException {
039            count+=b.length;
040            os.write(b);
041        }
042    
043        @Override
044        public void write(int b) throws IOException {
045            count++;
046            os.write(b);
047        }
048    
049        /**
050         * @return Returns the count.
051         */
052        public int getCount() {
053            return count;
054        }
055    
056    }