@Test public void seekTest() throws IOException { for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) { for (WriteType op : WriteType.values()) { int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k); TachyonFile file = mTfs.getFile(fileId); InStream is = (k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE)); Assert.assertTrue(is instanceof FileInStream); is.seek(k / 3); Assert.assertEquals(k / 3, is.read()); is.seek(k / 2); Assert.assertEquals(k / 2, is.read()); is.seek(k / 4); Assert.assertEquals(k / 4, is.read()); is.close(); } } }
@Override public void seek(long pos) throws IOException { if (mCurrentPosition == pos) { return; } if (pos < 0) { throw new IOException("pos is negative: " + pos); } if ((int) (pos / BLOCK_CAPACITY) != mCurrentBlockIndex) { mCurrentBlockIndex = (int) (pos / BLOCK_CAPACITY); if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); } mCurrentBlockInStream.seek(pos % BLOCK_CAPACITY); mCurrentPosition = pos; mCurrentBlockLeft = BLOCK_CAPACITY - (pos % BLOCK_CAPACITY); }
FileInStream extends InStream { @Override public void seek(long pos) throws IOException { if (mCurrentPosition == pos) { return; } if (pos < 0) { throw new IOException("pos is negative: " + pos); } if ((int) (pos / BLOCK_CAPACITY) != mCurrentBlockIndex) { mCurrentBlockIndex = (int) (pos / BLOCK_CAPACITY); if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); } mCurrentBlockInStream.seek(pos % BLOCK_CAPACITY); mCurrentPosition = pos; mCurrentBlockLeft = BLOCK_CAPACITY - (pos % BLOCK_CAPACITY); } }
FileInStream extends InStream { @Override public void seek(long pos) throws IOException { if (mCurrentPosition == pos) { return; } if (pos < 0) { throw new IOException("pos is negative: " + pos); } if ((int) (pos / BLOCK_CAPACITY) != mCurrentBlockIndex) { mCurrentBlockIndex = (int) (pos / BLOCK_CAPACITY); if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); } mCurrentBlockInStream.seek(pos % BLOCK_CAPACITY); mCurrentPosition = pos; mCurrentBlockLeft = BLOCK_CAPACITY - (pos % BLOCK_CAPACITY); } FileInStream(TachyonFile file, ReadType opType);  FileInStream(TachyonFile file, ReadType opType, Object ufsConf); }
FileInStream extends InStream { @Override public void seek(long pos) throws IOException { if (mCurrentPosition == pos) { return; } if (pos < 0) { throw new IOException("pos is negative: " + pos); } if ((int) (pos / BLOCK_CAPACITY) != mCurrentBlockIndex) { mCurrentBlockIndex = (int) (pos / BLOCK_CAPACITY); if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); } mCurrentBlockInStream.seek(pos % BLOCK_CAPACITY); mCurrentPosition = pos; mCurrentBlockLeft = BLOCK_CAPACITY - (pos % BLOCK_CAPACITY); } FileInStream(TachyonFile file, ReadType opType);  FileInStream(TachyonFile file, ReadType opType, Object ufsConf); @Override void close(); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] b, int off, int len); @Override void seek(long pos); @Override long skip(long n); }
FileInStream extends InStream { @Override public void seek(long pos) throws IOException { if (mCurrentPosition == pos) { return; } if (pos < 0) { throw new IOException("pos is negative: " + pos); } if ((int) (pos / BLOCK_CAPACITY) != mCurrentBlockIndex) { mCurrentBlockIndex = (int) (pos / BLOCK_CAPACITY); if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); } mCurrentBlockInStream.seek(pos % BLOCK_CAPACITY); mCurrentPosition = pos; mCurrentBlockLeft = BLOCK_CAPACITY - (pos % BLOCK_CAPACITY); } FileInStream(TachyonFile file, ReadType opType);  FileInStream(TachyonFile file, ReadType opType, Object ufsConf); @Override void close(); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] b, int off, int len); @Override void seek(long pos); @Override long skip(long n);  }