@Override public int read(byte[] b, int off, int len) throws IOException { int n = stream.read(b, off, len); if (n >= 0) fp += n; else n = 0; markManager(); while (n < len && fp < length()) { int s = stream.read(b, off + n, len - n); fp += s; n += s; } return n == -1 ? 0 : n; }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public int readUnsignedShort() throws IOException { return readShort() & 0xffff; }
@Override public int skipBytes(int n) throws IOException { int skipped = 0; try { for (int i=0; i<n; i++) { if (readUnsignedByte() != -1) skipped++; markManager(); } } catch (EOFException e) { } return skipped; }
@Override public void seek(long pos) throws IOException { LOGGER.trace("{}", pos); long diff = pos - fp; fp = pos; if (diff < 0) { // resetStream sets the fp to 0 resetStream(); diff = pos; fp = pos; } int skipped = stream.skipBytes((int) diff); while (skipped < diff) { int n = stream.skipBytes((int) (diff - skipped)); if (n == 0) break; skipped += n; } markManager(); }
@Override public void write(ByteBuffer buf) throws IOException { write(buf, 0, buf.capacity()); }
/** * @see StreamHandle#seek(long) */ @Override public void seek(long pos) throws IOException { LOGGER.trace("{}", pos); if (this.stat == null || this.objectNotFound != null) { throw new DelayedObjectNotFound(this); } long diff = pos - fp; if (diff < 0 || diff > S3_MAX_FORWARD_SEEK) { resetStream(pos); } else { super.seek(pos); } }
@Override public void close() throws IOException { super.close(); zip = null; entryName = null; if (in != null) in.close(); in = null; entryCount = 0; }
@Override public void seek(long pos) throws IOException { long diff = pos - fp; fp = pos; if (diff < 0) { resetStream(); diff = fp; } int skipped = stream.skipBytes((int) diff); while (skipped < diff) { int n = stream.skipBytes((int) (diff - skipped)); if (n == 0) break; skipped += n; } }
@Override public int skipBytes(int n) throws IOException { return (int) skipBytes((long) n); }
@Override public long skipBytes(long n) throws IOException { long skipped = 0; try { for (long i=0; i<n; i++) { if (readUnsignedByte() != -1) skipped++; markManager(); } } catch (EOFException e) { } return skipped; }
@Override public void seek(long pos) throws IOException { if (pos < fp && pos >= mark) { stream.reset(); fp = mark; skip(pos - fp); } else super.seek(pos); }
@Override public void close() throws IOException { super.close(); zip = null; entryName = null; if (in != null) in.close(); in = null; entryCount = 0; }
@Override public int read(byte[] b, int off, int len) throws IOException { LOGGER.trace("{} {}", off, len); int n = stream.read(b, off, len); if (n >= 0) fp += n; else n = 0; markManager(); while (n < len && fp < length()) { int s = stream.read(b, off + n, len - n); fp += s; n += s; } return n == -1 ? 0 : n; }
@Override public int read(byte[] b) throws IOException { LOGGER.trace("0 {}", b.length); return read(b, 0, b.length); }
@Override public void write(ByteBuffer buf) throws IOException { LOGGER.trace("0 {}", buf.capacity()); write(buf, 0, buf.capacity()); }
@Override public void seek(long pos) throws IOException { if (pos < fp && pos >= mark) { stream.reset(); fp = mark; skip(pos - fp); } else super.seek(pos); }
@Override public int readUnsignedShort() throws IOException { return readShort() & 0xffff; }
@Override public int read(ByteBuffer buffer) throws IOException { return read(buffer, 0, buffer.capacity()); }