class LimitedInputStream extends InputStream {

    @Override
    public int read() throws IOException {
        if (bytesRead >= limit) {
            return -1;
        }

        final int val = in.read();
        if (val > -1) {
            bytesRead++;
        }
        return val;
    }

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

}