1 package net.sf.openrocket.util;
3 import java.io.FilterInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
8 * A filtering InputStream that limits the number of bytes that can be
9 * read from a stream. This can be used to enforce security, so that overlong
12 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
14 public class LimitedInputStream extends FilterInputStream {
16 private int remaining;
18 public LimitedInputStream(InputStream is, int limit) {
20 this.remaining = limit;
25 public int available() throws IOException {
26 int available = super.available();
27 return Math.min(available, remaining);
32 public int read(byte[] b, int off, int len) throws IOException {
36 int result = super.read(b, off, Math.min(len, remaining));
44 public long skip(long n) throws IOException {
47 long result = super.skip(n);
54 public int read() throws IOException {
58 int result = super.read();
66 // Disable mark support
69 public void mark(int readlimit) {
74 public boolean markSupported() {
79 public synchronized void reset() throws IOException {
80 throw new IOException("mark/reset not supported");