@Override public long skip(long length) { int availableBytes = availableBytes(); // is skip within the current buffer? if (availableBytes >= length) { bufferPosition += length; return length; } // drop current buffer bufferPosition = bufferFill; try { // skip the rest in inputStream long inputStreamSkip = inputStream.skip(length - availableBytes); bufferOffset += inputStreamSkip; return availableBytes + inputStreamSkip; } catch (IOException e) { throw new UncheckedIOException(e); } }
@Override public void readBytes(OutputStream out, int length) throws IOException { while (length > 0) { int batch = Math.min(availableBytes(), length); out.write(buffer, bufferPosition, batch); bufferPosition += batch; length -= batch; ensureAvailable(Math.min(length, MINIMUM_CHUNK_SIZE)); } }
@Override public long skip(long length) { int availableBytes = availableBytes(); // is skip within the current buffer? if (availableBytes >= length) { bufferPosition += length; return length; } // drop current buffer bufferPosition = bufferFill; try { // skip the rest in inputStream long inputStreamSkip = inputStream.skip(length - availableBytes); bufferOffset += inputStreamSkip; return availableBytes + inputStreamSkip; } catch (IOException e) { throw new UncheckedIOException(e); } }
@Override public int available() { if (bufferPosition < bufferFill) { return availableBytes(); } return fillBuffer(); }
@Override public int available() { if (bufferPosition < bufferFill) { return availableBytes(); } return fillBuffer(); }
@Override public void readBytes(OutputStream out, int length) throws IOException { while (length > 0) { int batch = Math.min(availableBytes(), length); out.write(buffer, bufferPosition, batch); bufferPosition += batch; length -= batch; ensureAvailable(Math.min(length, MINIMUM_CHUNK_SIZE)); } }
@Override public int read(byte[] destination, int destinationIndex, int length) { if (available() == 0) { return -1; } verify(availableBytes() > 0); int batch = Math.min(availableBytes(), length); slice.getBytes(bufferPosition, destination, destinationIndex, batch); bufferPosition += batch; return batch; }
@Override public void readBytes(Slice destination, int destinationIndex, int length) { while (length > 0) { int batch = Math.min(availableBytes(), length); slice.getBytes(bufferPosition, destination, destinationIndex, batch); bufferPosition += batch; destinationIndex += batch; length -= batch; ensureAvailable(Math.min(length, MINIMUM_CHUNK_SIZE)); } }
@Override public int read(byte[] destination, int destinationIndex, int length) { if (available() == 0) { return -1; } verify(availableBytes() > 0); int batch = Math.min(availableBytes(), length); slice.getBytes(bufferPosition, destination, destinationIndex, batch); bufferPosition += batch; return batch; }
@Override public void readBytes(byte[] destination, int destinationIndex, int length) { while (length > 0) { int batch = Math.min(availableBytes(), length); slice.getBytes(bufferPosition, destination, destinationIndex, batch); bufferPosition += batch; destinationIndex += batch; length -= batch; ensureAvailable(Math.min(length, MINIMUM_CHUNK_SIZE)); } }
@Override public void readBytes(Slice destination, int destinationIndex, int length) { while (length > 0) { int batch = Math.min(availableBytes(), length); slice.getBytes(bufferPosition, destination, destinationIndex, batch); bufferPosition += batch; destinationIndex += batch; length -= batch; ensureAvailable(Math.min(length, MINIMUM_CHUNK_SIZE)); } }
@Override public void readBytes(byte[] destination, int destinationIndex, int length) { while (length > 0) { int batch = Math.min(availableBytes(), length); slice.getBytes(bufferPosition, destination, destinationIndex, batch); bufferPosition += batch; destinationIndex += batch; length -= batch; ensureAvailable(Math.min(length, MINIMUM_CHUNK_SIZE)); } }
@Override public int read() { if (available() == 0) { return -1; } verify(availableBytes() > 0); int v = slice.getByteUnchecked(bufferPosition) & 0xFF; bufferPosition += SIZE_OF_BYTE; return v; }
@Override public int read() { if (available() == 0) { return -1; } verify(availableBytes() > 0); int v = slice.getByteUnchecked(bufferPosition) & 0xFF; bufferPosition += SIZE_OF_BYTE; return v; }