@Test public void testSeek() throws IOException { int seekAmount = (int) (BLOCK_LENGTH / 2); int readAmount = (int) (BLOCK_LENGTH * 2); byte[] buffer = new byte[readAmount]; mTestStream.seek(seekAmount); mTestStream.read(buffer); assertArrayEquals(BufferUtils.getIncreasingByteArray(seekAmount, readAmount), buffer); byte[] expected = mBlockSource != BlockInStreamSource.REMOTE ? new byte[0] : BufferUtils.getIncreasingByteArray((int) BLOCK_LENGTH, (int) BLOCK_LENGTH); mTestStream.seek(seekAmount + readAmount); mTestStream.seek((long) (BLOCK_LENGTH * 3.1)); assertEquals(BufferUtils.byteToInt((byte) (BLOCK_LENGTH * 3.1)), mTestStream.read()); mTestStream.seek(FILE_LENGTH); }
@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);  }