class LimitedInputStream extends InputStream {

    @Override
    public long skip(final long n) throws IOException {
        final long skipped = in.skip(Math.min(n, limit - bytesRead));
        bytesRead += skipped;
        return skipped;
    }

    public  LimitedInputStream(final InputStream in, final long limit);

}