/** * Wraps the raw table stream. This is used to create the charPos and * filePos streams. The streams that this method returns are "safe", * meaning that the charPos and filePos position() fields never clobber * each other. They are buffered, meaning that up to <i>n</i> elements * can be read before the disk is accessed again. And they are "origined", * meaning result.position(0) actually positions the stream at the * beginning of the piece table array, not the beginning of the file. * * @param input the stream to wrap * @param pos the origin for the returned stream * @param cache the number of bytes for the returned stream to buffer * @return the wrapped stream * @throws IOException if an IO error occurs */ private SeekInputStream wrap(SeekInputStream input, long pos, int cache) throws IOException { input.position(pos); SeekInputStream r = new SafeSeekInputStream(input); r = new OriginSeekInputStream(r, pos); r = new BufferedSeekInputStream(r, cache); return r; }
@Override public int read() throws IOException { ensure(); int c = input.read(); if (c >= 0) { expected++; } return c; }
@Override public int read() throws IOException { ensure(); int c = input.read(); if (c >= 0) { expected++; } return c; }
@Override public long skip(long c) throws IOException { ensure(); long r = input.skip(c); if (r > 0) { expected += r; } return r; }
/** * Wraps the raw table stream. This is used to create the charPos and * filePos streams. The streams that this method returns are "safe", * meaning that the charPos and filePos position() fields never clobber * each other. They are buffered, meaning that up to <i>n</i> elements * can be read before the disk is accessed again. And they are "origined", * meaning result.position(0) actually positions the stream at the * beginning of the piece table array, not the beginning of the file. * * @param input the stream to wrap * @param pos the origin for the returned stream * @param cache the number of bytes for the returned stream to buffer * @return the wrapped stream * @throws IOException if an IO error occurs */ private SeekInputStream wrap(SeekInputStream input, long pos, int cache) throws IOException { input.position(pos); SeekInputStream r = new SafeSeekInputStream(input); r = new OriginSeekInputStream(r, pos); r = new BufferedSeekInputStream(r, cache); return r; }
@Override public long skip(long c) throws IOException { ensure(); long r = input.skip(c); if (r > 0) { expected += r; } return r; }
@Override public int read(byte[] buf, int ofs, int len) throws IOException { ensure(); int r = input.read(buf, ofs, len); if (r > 0) { expected += r; } return r; }
@Override public int read() throws IOException { ensure(); int c = input.read(); if (c >= 0) { expected++; } return c; }
@Override public int read(byte[] buf) throws IOException { ensure(); int r = input.read(buf); if (r > 0) { expected += r; } return r; }
@Override public int read(byte[] buf) throws IOException { ensure(); int r = input.read(buf); if (r > 0) { expected += r; } return r; }
@Override public int read(byte[] buf, int ofs, int len) throws IOException { ensure(); int r = input.read(buf, ofs, len); if (r > 0) { expected += r; } return r; }
@Override public int read(byte[] buf) throws IOException { ensure(); int r = input.read(buf); if (r > 0) { expected += r; } return r; }
@Override public int read(byte[] buf, int ofs, int len) throws IOException { ensure(); int r = input.read(buf, ofs, len); if (r > 0) { expected += r; } return r; }
@Override public long skip(long c) throws IOException { ensure(); long r = input.skip(c); if (r > 0) { expected += r; } return r; }