001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one or more
003 *  contributor license agreements.  See the NOTICE file distributed with
004 *  this work for additional information regarding copyright ownership.
005 *  The ASF licenses this file to You under the Apache License, Version 2.0
006 *  (the "License"); you may not use this file except in compliance with
007 *  the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 */
017package org.apache.commons.compress.utils;
018
019import java.io.InputStream;
020
021/**
022 * A stream that limits reading from a wrapped stream to a given number of bytes.
023 *
024 * @NotThreadSafe
025 * @since 1.6
026 * @deprecated Use {@link org.apache.commons.io.input.BoundedInputStream}.
027 */
028@Deprecated
029public class BoundedInputStream extends org.apache.commons.io.input.BoundedInputStream {
030
031    /**
032     * Creates the stream that will at most read the given amount of bytes from the given stream.
033     *
034     * @param in   the stream to read from
035     * @param size the maximum amount of bytes to read
036     */
037    public BoundedInputStream(final InputStream in, final long size) {
038        super(in, size);
039        setPropagateClose(false);
040    }
041
042    /**
043     * Gets how many bytes remain to read.
044     *
045     * @return bytes how many bytes remain to read.
046     * @since 1.21
047     */
048    public long getBytesRemaining() {
049        return getMaxCount() - getCount();
050    }
051
052//    @Override
053//    protected void onMaxLength(long maxLength, long count) throws IOException {
054//        if (count > maxLength) {
055//            throw new IOException("Can't read past EOF.");
056//        }
057//    }
058}