001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.commons.io;
020
021import java.io.IOException;
022import java.io.Reader;
023import java.nio.CharBuffer;
024
025public final class CountingReader extends Reader {
026        
027        private final Reader reader;
028    private int count=0;
029
030    public CountingReader(Reader reader) {
031        this.reader=reader;
032    }
033        @Override
034        public void mark(int readAheadLimit) throws IOException {
035                reader.mark(readAheadLimit);
036        }
037
038        @Override
039        public boolean markSupported() {
040                return reader.markSupported();
041        }
042
043        @Override
044        public int read() throws IOException {
045                count++;
046                return reader.read();
047        }
048
049        @Override
050        public int read(char[] cbuf) throws IOException {
051                
052                return reader.read(cbuf);
053        }
054
055        @Override
056        public int read(CharBuffer arg0) throws IOException {
057                return super.read(arg0.array());
058        }
059
060        @Override
061        public boolean ready() throws IOException {
062                // TODO Auto-generated method stub
063                return super.ready();
064        }
065
066        @Override
067        public void reset() throws IOException {
068                // TODO Auto-generated method stub
069                super.reset();
070        }
071
072        @Override
073        public long skip(long n) throws IOException {
074                // TODO Auto-generated method stub
075                return super.skip(n);
076        }
077
078        public void close() throws IOException {
079                // TODO Auto-generated method stub
080
081        }
082
083        public int read(char[] cbuf, int off, int len) throws IOException {
084                // TODO Auto-generated method stub
085                return 0;
086        }
087
088}