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