14fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/*
24fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Licensed to the Apache Software Foundation (ASF) under one or more
34fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * contributor license agreements.  See the NOTICE file distributed with
44fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * this work for additional information regarding copyright ownership.
54fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * The ASF licenses this file to You under the Apache License, Version 2.0
64fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * (the "License"); you may not use this file except in compliance with
74fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * the License.  You may obtain a copy of the License at
84fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *
94fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *      http://www.apache.org/licenses/LICENSE-2.0
104fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *
114fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Unless required by applicable law or agreed to in writing, software
124fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * distributed under the License is distributed on an "AS IS" BASIS,
134fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * See the License for the specific language governing permissions and
154fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * limitations under the License.
164fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */
174fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypackage org.apache.commons.io.input;
184fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
194fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedyimport java.io.FilterInputStream;
204fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedyimport java.io.IOException;
214fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedyimport java.io.InputStream;
224fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
234fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/**
244fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * A Proxy stream which acts as expected, that is it passes the method
254fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * calls on to the proxied stream and doesn't change which methods are
264fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * being called.
274fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * <p>
284fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * It is an alternative base class to FilterInputStream
294fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * to increase reusability, because FilterInputStream changes the
304fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * methods being called, such as read(byte[]) to read(byte[], int, int).
314fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *
324fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @author Stephen Colebourne
334fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @version $Id: ProxyInputStream.java 610010 2008-01-08 14:50:59Z niallp $
344fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */
354fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypublic abstract class ProxyInputStream extends FilterInputStream {
364fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
374fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
384fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Constructs a new ProxyInputStream.
394fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
404fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param proxy  the InputStream to delegate to
414fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
424fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public ProxyInputStream(InputStream proxy) {
434fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        super(proxy);
444fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        // the proxy is stored in a protected superclass variable named 'in'
454fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
464fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
474fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
484fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Invokes the delegate's <code>read()</code> method.
494fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return the byte read or -1 if the end of stream
504fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws IOException if an I/O error occurs
514fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
524fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public int read() throws IOException {
534fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return in.read();
544fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
554fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
564fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
574fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Invokes the delegate's <code>read(byte[])</code> method.
584fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param bts the buffer to read the bytes into
594fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return the number of bytes read or -1 if the end of stream
604fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws IOException if an I/O error occurs
614fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
624fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public int read(byte[] bts) throws IOException {
634fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return in.read(bts);
644fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
654fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
664fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
674fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Invokes the delegate's <code>read(byte[], int, int)</code> method.
684fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param bts the buffer to read the bytes into
694fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param st The start offset
704fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param end The number of bytes to read
714fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return the number of bytes read or -1 if the end of stream
724fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws IOException if an I/O error occurs
734fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
744fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public int read(byte[] bts, int st, int end) throws IOException {
754fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return in.read(bts, st, end);
764fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
774fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
784fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
794fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Invokes the delegate's <code>skip(long)</code> method.
804fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param ln the number of bytes to skip
814fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return the number of bytes to skipped or -1 if the end of stream
824fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws IOException if an I/O error occurs
834fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
844fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public long skip(long ln) throws IOException {
854fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return in.skip(ln);
864fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
874fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
884fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
894fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Invokes the delegate's <code>available()</code> method.
904fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return the number of available bytes
914fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws IOException if an I/O error occurs
924fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
934fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public int available() throws IOException {
944fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return in.available();
954fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
964fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
974fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
984fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Invokes the delegate's <code>close()</code> method.
994fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws IOException if an I/O error occurs
1004fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1014fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public void close() throws IOException {
1024fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        in.close();
1034fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1044fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1054fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1064fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Invokes the delegate's <code>mark(int)</code> method.
1074fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param idx read ahead limit
1084fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1094fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public synchronized void mark(int idx) {
1104fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        in.mark(idx);
1114fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1124fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1134fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1144fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Invokes the delegate's <code>reset()</code> method.
1154fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws IOException if an I/O error occurs
1164fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1174fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public synchronized void reset() throws IOException {
1184fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        in.reset();
1194fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1204fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1214fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1224fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Invokes the delegate's <code>markSupported()</code> method.
1234fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return true if mark is supported, otherwise false
1244fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1254fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public boolean markSupported() {
1264fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return in.markSupported();
1274fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1284fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1294fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy}
130