@Override public int read(byte[] b, int off, int len) throws IOException { int tmp = super.read(b, off, len); byteCount += tmp >= 0 ? tmp : 0; return tmp; } }
@Override public void close() throws IOException { // Only close the wrapped input stream if we're at the end of // the wrapped stream. We don't want to close the wrapped input // stream just because we've reached the end of one subsection. if (closeSourceStream) super.close(); }
@Override public synchronized void mark(int readlimit) { super.mark(readlimit); markedBytes = bytesRead; }
@Override public int read(byte[] b, int off, int len) throws IOException { int count = 0; while (currentPosition < requestedOffset) { long skippedBytes = super.skip(requestedOffset - currentPosition); if (skippedBytes == 0) { count++; if (count > MAX_SKIPS) { throw new SdkClientException( "Unable to position the currentPosition from " + currentPosition + " to " + requestedOffset); } } currentPosition += skippedBytes; } long bytesRemaining = (requestedLength + requestedOffset) - currentPosition; if (bytesRemaining <= 0) return -1; len = (int) Math.min(len, bytesRemaining); int bytesRead = super.read(b, off, len); currentPosition += bytesRead; return bytesRead; }
@Override public synchronized void reset() throws IOException { currentPosition = markedPosition; super.reset(); }
@Override public long skip(final long n) throws IOException { hasBeenAccessed = true; return super.skip(n); }
@Override public void reset() throws IOException { super.reset(); if (super.markSupported()) { dataLength = marked; } }
/** * Abort this stream, potentially before all events have been read. This should be used before {@link #close()} if there are * still events pending on the stream. Using this method has a performance impact, because it will forcibly close the active * connection to S3, whereas reading to end of the stream before calling {@link #close()} will still allow the connection to * be reused. */ public void abort() { inputStream.abort(); }
@Override public int read() throws IOException { abortIfNeeded(); return in.read(); }
/** * Returns the value of super.available() if the result is nonzero, or 1 * otherwise. * <p> * This is necessary to work around a known bug in * GZIPInputStream.available(), which returns zero in some edge cases, * causing file truncation. * <p> * Ref: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7036144 */ @Override public int available() throws IOException { int estimate = super.available(); return estimate == 0 ? 1 : estimate; }
@Override public boolean markSupported() { // Cloning of the digest is required to support restoring the prior state of the MD5 calculation when using mark() and // reset(). If the digest doesn't support cloning, we have to disable mark/reset support. return super.markSupported() && digestCanBeCloned; }
@Override public int read(byte[] b, int off, int len) throws IOException { while (currentPosition < requestedOffset) { long skippedBytes = super.skip(requestedOffset - currentPosition); currentPosition += skippedBytes; } long bytesRemaining = (requestedLength + requestedOffset) - currentPosition; if (bytesRemaining <= 0) return -1; len = (int) Math.min(len, bytesRemaining); int bytesRead = super.read(b, off, len); currentPosition += bytesRead; return bytesRead; }
/** * {@inheritDoc} */ @Override public synchronized void reset() throws IOException { super.reset(); bytesRead = markedBytes; eofReached = false; }
@Override public synchronized long skip(long n) throws IOException { try { long skipped = super.skip(n); if (skipped > 0) { bytesRead += skipped; } return skipped; } catch (Exception e) { return onException(e); } }
@Override public void reset() throws IOException { super.reset(); if (super.markSupported()) { dataLength = marked; } }
/** * Can be used to provide abortion logic prior to throwing the * AbortedException. If the wrapped {@code InputStream} is also an instance * of this class, then it will also be aborted, otherwise this is a no-op. */ public void abort() { if (in instanceof SdkFilterInputStream) { ((SdkFilterInputStream) in).abort(); } aborted = true; }
@Override public void close() throws IOException { in.close(); abortIfNeeded(); }
/** * Returns the value of super.available() if the result is nonzero, or 1 * otherwise. * <p> * This is necessary to work around a known bug in * GZIPInputStream.available(), which returns zero in some edge cases, * causing file truncation. * <p> * Ref: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7036144 */ @Override public int available() throws IOException { int estimate = super.available(); return estimate == 0 ? 1 : estimate; }
@Override public boolean markSupported() { // Cloning of the digest is required to support restoring the prior state of the MD5 calculation when using mark() and // reset(). If the digest doesn't support cloning, we have to disable mark/reset support. return super.markSupported() && digestCanBeCloned; }
@Override public int read() throws IOException { hasBeenAccessed = true; return super.read(); }