@Test public void seekPastEnd() throws IOException { try { mTestStream.seek(FILE_LENGTH + 1); fail("seeking past the end of the stream should fail"); } catch (IllegalArgumentException e) { assertEquals(String.format(PreconditionMessage.ERR_SEEK_PAST_END_OF_FILE.toString(), FILE_LENGTH + 1), e.getMessage()); } }
@Override public void seek(long pos) throws IOException { if (mPosition == pos) { return; } Preconditions.checkArgument(pos >= 0, PreconditionMessage.ERR_SEEK_NEGATIVE.toString(), pos); Preconditions.checkArgument(pos <= mLength, PreconditionMessage.ERR_SEEK_PAST_END_OF_FILE.toString(), pos); if (mBlockInStream == null) { mPosition = pos; return; } long delta = pos - mPosition; if (delta <= mBlockInStream.remaining() && delta >= -mBlockInStream.getPos()) { mBlockInStream.seek(mBlockInStream.getPos() + delta); } else { closeBlockInStream(mBlockInStream); } mPosition += delta; }
AlluxioFileInStream extends FileInStream { @Override public void seek(long pos) throws IOException { if (mPosition == pos) { return; } Preconditions.checkArgument(pos >= 0, PreconditionMessage.ERR_SEEK_NEGATIVE.toString(), pos); Preconditions.checkArgument(pos <= mLength, PreconditionMessage.ERR_SEEK_PAST_END_OF_FILE.toString(), pos); if (mBlockInStream == null) { mPosition = pos; return; } long delta = pos - mPosition; if (delta <= mBlockInStream.remaining() && delta >= -mBlockInStream.getPos()) { mBlockInStream.seek(mBlockInStream.getPos() + delta); } else { closeBlockInStream(mBlockInStream); } mPosition += delta; } }
AlluxioFileInStream extends FileInStream { @Override public void seek(long pos) throws IOException { if (mPosition == pos) { return; } Preconditions.checkArgument(pos >= 0, PreconditionMessage.ERR_SEEK_NEGATIVE.toString(), pos); Preconditions.checkArgument(pos <= mLength, PreconditionMessage.ERR_SEEK_PAST_END_OF_FILE.toString(), pos); if (mBlockInStream == null) { mPosition = pos; return; } long delta = pos - mPosition; if (delta <= mBlockInStream.remaining() && delta >= -mBlockInStream.getPos()) { mBlockInStream.seek(mBlockInStream.getPos() + delta); } else { closeBlockInStream(mBlockInStream); } mPosition += delta; } protected  AlluxioFileInStream(URIStatus status, InStreamOptions options,
      FileSystemContext context); }
AlluxioFileInStream extends FileInStream { @Override public void seek(long pos) throws IOException { if (mPosition == pos) { return; } Preconditions.checkArgument(pos >= 0, PreconditionMessage.ERR_SEEK_NEGATIVE.toString(), pos); Preconditions.checkArgument(pos <= mLength, PreconditionMessage.ERR_SEEK_PAST_END_OF_FILE.toString(), pos); if (mBlockInStream == null) { mPosition = pos; return; } long delta = pos - mPosition; if (delta <= mBlockInStream.remaining() && delta >= -mBlockInStream.getPos()) { mBlockInStream.seek(mBlockInStream.getPos() + delta); } else { closeBlockInStream(mBlockInStream); } mPosition += delta; } protected  AlluxioFileInStream(URIStatus status, InStreamOptions options,
      FileSystemContext context); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] b, int off, int len); @Override long skip(long n); @Override void close(); @Override long remaining(); @Override int positionedRead(long pos, byte[] b, int off, int len); @Override long getPos(); @Override void seek(long pos); }
AlluxioFileInStream extends FileInStream { @Override public void seek(long pos) throws IOException { if (mPosition == pos) { return; } Preconditions.checkArgument(pos >= 0, PreconditionMessage.ERR_SEEK_NEGATIVE.toString(), pos); Preconditions.checkArgument(pos <= mLength, PreconditionMessage.ERR_SEEK_PAST_END_OF_FILE.toString(), pos); if (mBlockInStream == null) { mPosition = pos; return; } long delta = pos - mPosition; if (delta <= mBlockInStream.remaining() && delta >= -mBlockInStream.getPos()) { mBlockInStream.seek(mBlockInStream.getPos() + delta); } else { closeBlockInStream(mBlockInStream); } mPosition += delta; } protected  AlluxioFileInStream(URIStatus status, InStreamOptions options,
      FileSystemContext context); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] b, int off, int len); @Override long skip(long n); @Override void close(); @Override long remaining(); @Override int positionedRead(long pos, byte[] b, int off, int len); @Override long getPos(); @Override void seek(long pos);  }