@Override public int available() { checkClosed(); if (buffer == null) { return 0; } else { return buffer.length - bufferOffset; } }
@Override public synchronized void reset() { checkClosed(); if (currentPosition == markPosition) { return; } bufferOffset = (int) (markPosition % chunkSizeInBytes); currentPosition = markPosition; int markChunkIndex = (int) Math.floor(markPosition / (double) chunkSizeInBytes); if (markChunkIndex != chunkIndex) { chunkIndex = markChunkIndex; buffer = null; discardCursor(); } }
@Override public int read(final byte[] b, final int off, final int len) { checkClosed(); if (currentPosition == length) { return -1; } else if (buffer == null) { buffer = getBuffer(chunkIndex); } else if (bufferOffset == buffer.length) { chunkIndex += 1; buffer = getBuffer(chunkIndex); bufferOffset = 0; } int r = Math.min(len, buffer.length - bufferOffset); System.arraycopy(buffer, bufferOffset, b, off, r); bufferOffset += r; currentPosition += r; return r; }
@Override public long skip(final long bytesToSkip) { checkClosed(); if (bytesToSkip <= 0) { return 0; } long skippedPosition = currentPosition + bytesToSkip; bufferOffset = (int) (skippedPosition % chunkSizeInBytes); if (skippedPosition >= length) { long skipped = length - currentPosition; chunkIndex = numberOfChunks - 1; currentPosition = length; buffer = null; discardCursor(); return skipped; } else { int newChunkIndex = (int) Math.floor(skippedPosition / (double) chunkSizeInBytes); if (chunkIndex != newChunkIndex) { chunkIndex = newChunkIndex; buffer = null; discardCursor(); } currentPosition += bytesToSkip; return bytesToSkip; } }
@Override public int available() { checkClosed(); if (buffer == null) { return 0; } else { return buffer.length - bufferOffset; } }
@Override public int available() { checkClosed(); if (buffer == null) { return 0; } else { return buffer.length - bufferOffset; } }
@Override public synchronized void reset() { checkClosed(); if (currentPosition == markPosition) { return; } bufferOffset = (int) (markPosition % chunkSizeInBytes); currentPosition = markPosition; int markChunkIndex = (int) Math.floor(markPosition / (double) chunkSizeInBytes); if (markChunkIndex != chunkIndex) { chunkIndex = markChunkIndex; buffer = null; discardCursor(); } }
@Override public synchronized void reset() { checkClosed(); if (currentPosition == markPosition) { return; } bufferOffset = (int) (markPosition % chunkSizeInBytes); currentPosition = markPosition; int markChunkIndex = (int) Math.floor(markPosition / (double) chunkSizeInBytes); if (markChunkIndex != chunkIndex) { chunkIndex = markChunkIndex; buffer = null; discardCursor(); } }
@Override public int read(final byte[] b, final int off, final int len) { checkClosed(); if (currentPosition == length) { return -1; } else if (buffer == null) { buffer = getBuffer(chunkIndex); } else if (bufferOffset == buffer.length) { chunkIndex += 1; buffer = getBuffer(chunkIndex); bufferOffset = 0; } int r = Math.min(len, buffer.length - bufferOffset); System.arraycopy(buffer, bufferOffset, b, off, r); bufferOffset += r; currentPosition += r; return r; }
@Override public int read(final byte[] b, final int off, final int len) { checkClosed(); if (currentPosition == length) { return -1; } else if (buffer == null) { buffer = getBuffer(chunkIndex); } else if (bufferOffset == buffer.length) { chunkIndex += 1; buffer = getBuffer(chunkIndex); bufferOffset = 0; } int r = Math.min(len, buffer.length - bufferOffset); System.arraycopy(buffer, bufferOffset, b, off, r); bufferOffset += r; currentPosition += r; return r; }
@Override public long skip(final long bytesToSkip) { checkClosed(); if (bytesToSkip <= 0) { return 0; } long skippedPosition = currentPosition + bytesToSkip; bufferOffset = (int) (skippedPosition % chunkSizeInBytes); if (skippedPosition >= length) { long skipped = length - currentPosition; chunkIndex = numberOfChunks - 1; currentPosition = length; buffer = null; discardCursor(); return skipped; } else { int newChunkIndex = (int) Math.floor(skippedPosition / (double) chunkSizeInBytes); if (chunkIndex != newChunkIndex) { chunkIndex = newChunkIndex; buffer = null; discardCursor(); } currentPosition += bytesToSkip; return bytesToSkip; } }
@Override public long skip(final long bytesToSkip) { checkClosed(); if (bytesToSkip <= 0) { return 0; } long skippedPosition = currentPosition + bytesToSkip; bufferOffset = (int) (skippedPosition % chunkSizeInBytes); if (skippedPosition >= length) { long skipped = length - currentPosition; chunkIndex = numberOfChunks - 1; currentPosition = length; buffer = null; discardCursor(); return skipped; } else { int newChunkIndex = (int) Math.floor(skippedPosition / (double) chunkSizeInBytes); if (chunkIndex != newChunkIndex) { chunkIndex = newChunkIndex; buffer = null; discardCursor(); } currentPosition += bytesToSkip; return bytesToSkip; } }