class LimitedInputStream extends FilterInputStream implements Closeable {

    private final long sizeMax;
    private long count;

    public LimitedInputStream(final InputStream inputStream, final long limitSize) {
        super(inputStream);
        sizeMax = limitSize;
    }

    protected void raiseError(long pSizeMax, long pCount) throws IOException {
        throw new LimitedInputException("The input stream is too large: " + pSizeMax);
    }


    private void checkLimit() throws IOException {
        if (sizeMax > 0 && count > sizeMax) {
            raiseError(sizeMax, count);
        }
    }

    @Override
    public int read() throws IOException {
        final int res = super.read();
        if (res != -1) {
            count++;
            checkLimit();
        }
        return res;
    }

    @Override
    public int read(final byte[] b, final int off, final int len) throws IOException {<FILL_FUNCTION_BODY>}

    @Override
    public void close() throws IOException {
        super.close();
    }
}

        final int res = super.read(b, off, len);
        if (res > 0) {
            count += res;
            checkLimit();
        }
        return res;
    
<methods>public int available() throws java.io.IOException,public void close() throws java.io.IOException,public synchronized void mark(int) ,public boolean markSupported() ,public int read() throws java.io.IOException,public int read(byte[]) throws java.io.IOException,public int read(byte[], int, int) throws java.io.IOException,public synchronized void reset() throws java.io.IOException,public long skip(long) throws java.io.IOException<variables>protected volatile java.io.InputStream in