@Override public void seek(long pos) throws IOException { if (mPos == pos) { return; } Preconditions.checkArgument(pos >= 0, PreconditionMessage.ERR_SEEK_NEGATIVE, pos); Preconditions.checkArgument(pos < mFileLength, PreconditionMessage.ERR_SEEK_PAST_END_OF_FILE, pos); seekBlockInStream(pos); checkAndAdvanceBlockInStream(); mCurrentBlockInStream.seek(mPos % mBlockSize); }
@Override public long skip(long n) throws IOException { if (n <= 0) { return 0; } long toSkip = Math.min(n, mFileLength - mPos); long newPos = mPos + toSkip; long toSkipInBlock = ((newPos / mBlockSize) > mPos / mBlockSize) ? newPos % mBlockSize : toSkip; seekBlockInStream(newPos); checkAndAdvanceBlockInStream(); if (toSkipInBlock != mCurrentBlockInStream.skip(toSkipInBlock)) { throw new IOException(ExceptionMessage.INSTREAM_CANNOT_SKIP.getMessage(toSkip)); } return toSkip; }