@Override public int read(byte[] b, int off, int len) throws IOException { if (len == 0) return 0; int copied = 0; while (0 < len) { int c = Math.min(block.count - blockPos, len); if (0 < c) { System.arraycopy(block.buffer, blockPos, b, off, c); blockPos += c; off += c; len -= c; copied += c; } else if (nextBlock()) continue; else break; } return 0 < copied ? copied : -1; }
@Override public int read(byte[] b, int off, int len) throws IOException { if (len == 0) return 0; int copied = 0; while (0 < len) { int c = Math.min(block.count - blockPos, len); if (0 < c) { System.arraycopy(block.buffer, blockPos, b, off, c); blockPos += c; off += c; len -= c; copied += c; } else if (nextBlock()) continue; else break; } return 0 < copied ? copied : -1; }
/** * Same as {@link #openInputStream()} but handling destruction of any * associated resources automatically when closing the returned stream. * * @return an InputStream which will automatically destroy any associated * temporary file on {@link #close()} * @throws IOException * in case of an error. * @since 4.11 */ public InputStream openInputStreamWithAutoDestroy() throws IOException { return new BlockInputStream() { @Override public void close() throws IOException { super.close(); destroy(); } }; }
@Override public int read(byte[] b, int off, int len) throws IOException { if (len == 0) return 0; int copied = 0; while (0 < len) { int c = Math.min(block.count - blockPos, len); if (0 < c) { System.arraycopy(block.buffer, blockPos, b, off, c); blockPos += c; off += c; len -= c; copied += c; } else if (nextBlock()) continue; else break; } return 0 < copied ? copied : -1; }
@Override public long skip(long cnt) throws IOException { long skipped = 0; while (0 < cnt) { int n = (int) Math.min(block.count - blockPos, cnt); if (0 < n) { blockPos += n; skipped += n; cnt -= n; } else if (nextBlock()) continue; else break; } return skipped; }
@Override public long skip(long cnt) throws IOException { long skipped = 0; while (0 < cnt) { int n = (int) Math.min(block.count - blockPos, cnt); if (0 < n) { blockPos += n; skipped += n; cnt -= n; } else if (nextBlock()) continue; else break; } return skipped; }
/** * Open an input stream to read from the buffered data. * <p> * This method may only be invoked after {@link #close()} has completed * normally, to ensure all data is completely transferred. * * @return a stream to read from the buffer. The caller must close the * stream when it is no longer useful. * @throws IOException * an error occurred opening the temporary file. */ public InputStream openInputStream() throws IOException { return new BlockInputStream(); }
@Override public void close() throws IOException { super.close(); destroy(); } };
/** * Open an input stream to read from the buffered data. * <p> * This method may only be invoked after {@link #close()} has completed * normally, to ensure all data is completely transferred. * * @return a stream to read from the buffer. The caller must close the * stream when it is no longer useful. * @throws java.io.IOException * an error occurred opening the temporary file. */ public InputStream openInputStream() throws IOException { return new BlockInputStream(); }
@Override public int read() throws IOException { if (singleByteBuffer == null) singleByteBuffer = new byte[1]; int n = read(singleByteBuffer); return n == 1 ? singleByteBuffer[0] & 0xff : -1; }
@Override public int read() throws IOException { if (singleByteBuffer == null) singleByteBuffer = new byte[1]; int n = read(singleByteBuffer); return n == 1 ? singleByteBuffer[0] & 0xff : -1; }
/** * Same as {@link #openInputStream()} but handling destruction of any * associated resources automatically when closing the returned stream. * * @return an InputStream which will automatically destroy any associated * temporary file on {@link #close()} * @throws IOException * in case of an error. * @since 4.11 */ public InputStream openInputStreamWithAutoDestroy() throws IOException { return new BlockInputStream() { @Override public void close() throws IOException { super.close(); destroy(); } }; }
@Override public long skip(long cnt) throws IOException { long skipped = 0; while (0 < cnt) { int n = (int) Math.min(block.count - blockPos, cnt); if (0 < n) { blockPos += n; skipped += n; cnt -= n; } else if (nextBlock()) continue; else break; } return skipped; }
/** * Open an input stream to read from the buffered data. * <p> * This method may only be invoked after {@link #close()} has completed * normally, to ensure all data is completely transferred. * * @return a stream to read from the buffer. The caller must close the * stream when it is no longer useful. * @throws java.io.IOException * an error occurred opening the temporary file. */ public InputStream openInputStream() throws IOException { return new BlockInputStream(); }
@Override public int read() throws IOException { if (singleByteBuffer == null) singleByteBuffer = new byte[1]; int n = read(singleByteBuffer); return n == 1 ? singleByteBuffer[0] & 0xff : -1; }
@Override public void close() throws IOException { super.close(); destroy(); } };