@Test public void skipTest() 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); Assert.assertEquals(k / 2, is.skip(k / 2)); Assert.assertEquals(k / 2, is.read()); is.close(); is = (k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE)); Assert.assertTrue(is instanceof FileInStream); Assert.assertEquals(k / 3, is.skip(k / 3)); Assert.assertEquals(k / 3, is.read()); is.close(); } } }
@Override public long skip(long n) throws IOException { if (n <= 0) { return 0; } long ret = n; if (mCurrentPosition + n >= FILE.length()) { ret = FILE.length() - mCurrentPosition; mCurrentPosition += ret; } else { mCurrentPosition += n; } int tBlockIndex = (int) (mCurrentPosition / BLOCK_CAPACITY); if (tBlockIndex != mCurrentBlockIndex) { if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockIndex = tBlockIndex; mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); long shouldSkip = mCurrentPosition % BLOCK_CAPACITY; long skip = mCurrentBlockInStream.skip(shouldSkip); mCurrentBlockLeft = BLOCK_CAPACITY - skip; if (skip != shouldSkip) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + shouldSkip); } } else { long skip = mCurrentBlockInStream.skip(ret); if (skip != ret) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + ret); } } return ret; }
FileInStream extends InStream { @Override public long skip(long n) throws IOException { if (n <= 0) { return 0; } long ret = n; if (mCurrentPosition + n >= FILE.length()) { ret = FILE.length() - mCurrentPosition; mCurrentPosition += ret; } else { mCurrentPosition += n; } int tBlockIndex = (int) (mCurrentPosition / BLOCK_CAPACITY); if (tBlockIndex != mCurrentBlockIndex) { if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockIndex = tBlockIndex; mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); long shouldSkip = mCurrentPosition % BLOCK_CAPACITY; long skip = mCurrentBlockInStream.skip(shouldSkip); mCurrentBlockLeft = BLOCK_CAPACITY - skip; if (skip != shouldSkip) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + shouldSkip); } } else { long skip = mCurrentBlockInStream.skip(ret); if (skip != ret) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + ret); } } return ret; } }
FileInStream extends InStream { @Override public long skip(long n) throws IOException { if (n <= 0) { return 0; } long ret = n; if (mCurrentPosition + n >= FILE.length()) { ret = FILE.length() - mCurrentPosition; mCurrentPosition += ret; } else { mCurrentPosition += n; } int tBlockIndex = (int) (mCurrentPosition / BLOCK_CAPACITY); if (tBlockIndex != mCurrentBlockIndex) { if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockIndex = tBlockIndex; mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); long shouldSkip = mCurrentPosition % BLOCK_CAPACITY; long skip = mCurrentBlockInStream.skip(shouldSkip); mCurrentBlockLeft = BLOCK_CAPACITY - skip; if (skip != shouldSkip) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + shouldSkip); } } else { long skip = mCurrentBlockInStream.skip(ret); if (skip != ret) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + ret); } } return ret; } FileInStream(TachyonFile file, ReadType opType);  FileInStream(TachyonFile file, ReadType opType, Object ufsConf); }
FileInStream extends InStream { @Override public long skip(long n) throws IOException { if (n <= 0) { return 0; } long ret = n; if (mCurrentPosition + n >= FILE.length()) { ret = FILE.length() - mCurrentPosition; mCurrentPosition += ret; } else { mCurrentPosition += n; } int tBlockIndex = (int) (mCurrentPosition / BLOCK_CAPACITY); if (tBlockIndex != mCurrentBlockIndex) { if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockIndex = tBlockIndex; mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); long shouldSkip = mCurrentPosition % BLOCK_CAPACITY; long skip = mCurrentBlockInStream.skip(shouldSkip); mCurrentBlockLeft = BLOCK_CAPACITY - skip; if (skip != shouldSkip) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + shouldSkip); } } else { long skip = mCurrentBlockInStream.skip(ret); if (skip != ret) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + ret); } } return ret; } 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 long skip(long n) throws IOException { if (n <= 0) { return 0; } long ret = n; if (mCurrentPosition + n >= FILE.length()) { ret = FILE.length() - mCurrentPosition; mCurrentPosition += ret; } else { mCurrentPosition += n; } int tBlockIndex = (int) (mCurrentPosition / BLOCK_CAPACITY); if (tBlockIndex != mCurrentBlockIndex) { if (mCurrentBlockInStream != null) { mCurrentBlockInStream.close(); } mCurrentBlockIndex = tBlockIndex; mCurrentBlockInStream = BlockInStream.get(FILE, READ_TYPE, mCurrentBlockIndex, mUFSConf); long shouldSkip = mCurrentPosition % BLOCK_CAPACITY; long skip = mCurrentBlockInStream.skip(shouldSkip); mCurrentBlockLeft = BLOCK_CAPACITY - skip; if (skip != shouldSkip) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + shouldSkip); } } else { long skip = mCurrentBlockInStream.skip(ret); if (skip != ret) { throw new IOException("The underlayer BlockInStream only skip " + skip + " instead of " + ret); } } return ret; } 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);  }