org.apache.hadoop.fs.FSDataInputStream - java examples

Here are the examples of the java api org.apache.hadoop.fs.FSDataInputStream taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : TestPread.java
Copyright Apache License 2.0
Author : aliyun-beta
private void doPread(FSDataInputStream stm, long position, byte[] buffer, int offset, int length) throws IOException {
    int nread = 0;
    long totalRead = 0;
    DFSInputStream dfstm = null;
    if (stm.getWrappedStream() instanceof DFSInputStream) {
        dfstm = (DFSInputStream) (stm.getWrappedStream());
        totalRead = dfstm.getReadStatistics().getTotalBytesRead();
    }
    while (nread < length) {
        int nbytes = stm.read(position + nread, buffer, offset + nread, length - nread);
        replacedertTrue("Error in pread", nbytes > 0);
        nread += nbytes;
    }
    if (dfstm != null) {
        if (isHedgedRead) {
            replacedertTrue("Expected read statistic to be incremented", length <= dfstm.getReadStatistics().getTotalBytesRead() - totalRead);
        } else {
            replacedertEquals("Expected read statistic to be incremented", length, dfstm.getReadStatistics().getTotalBytesRead() - totalRead);
        }
    }
}

19 View Complete Implementation : TestHadoopArchives.java
Copyright Apache License 2.0
Author : aliyun-beta
private static void expectSeekIOE(FSDataInputStream fsdis, long seekPos, String message) {
    try {
        fsdis.seek(seekPos);
        replacedertTrue(message + " (Position = " + fsdis.getPos() + ")", false);
    } catch (IOException ioe) {
    // okay
    }
}

19 View Complete Implementation : ITestPageBlobInputStream.java
Copyright Apache License 2.0
Author : apache
private void verifyConsistentReads(FSDataInputStream inputStream, byte[] buffer, long position) throws IOException {
    int size = buffer.length;
    final int numBytesRead = inputStream.read(buffer, 0, size);
    replacedertEquals("Bytes read from stream", size, numBytesRead);
    byte[] expected = new byte[size];
    for (int i = 0; i < expected.length; i++) {
        expected[i] = (byte) ((position + i) % 256);
    }
    replacedertArrayEquals("Mismatch", expected, buffer);
}

19 View Complete Implementation : ITestAzureBlobFileSystemRandomRead.java
Copyright Apache License 2.0
Author : apache
private void verifyConsistentReads(FSDataInputStream inputStreamV1, FSDataInputStream inputStreamV2, byte[] bufferV1, byte[] bufferV2) throws IOException {
    int size = bufferV1.length;
    final int numBytesReadV1 = inputStreamV1.read(bufferV1, 0, size);
    replacedertEquals("Bytes read from wasb stream", size, numBytesReadV1);
    final int numBytesReadV2 = inputStreamV2.read(bufferV2, 0, size);
    replacedertEquals("Bytes read from abfs stream", size, numBytesReadV2);
    replacedertArrayEquals("Mismatch in read data", bufferV1, bufferV2);
}

19 View Complete Implementation : AbstractS3SelectTest.java
Copyright Apache License 2.0
Author : apache
/**
 * Execute a seek so far past the EOF that it will be rejected.
 * If the seek did not fail, the exception raised includes the toString()
 * value of the stream.
 * @param seekStream stream to seek in.
 * @param newpos new position
 * @return the EOF Exception raised.
 * @throws Exception any other exception.
 */
protected EOFException expectSeekEOF(final FSDataInputStream seekStream, final int newpos) throws Exception {
    return intercept(EOFException.clreplaced, () -> {
        seek(seekStream, newpos);
        // return this for the test failure reports.
        return "Stream after seek to " + newpos + ": " + seekStream;
    });
}

19 View Complete Implementation : TestPread.java
Copyright Apache License 2.0
Author : apache
private void doPread(FSDataInputStream stm, long position, byte[] buffer, int offset, int length) throws IOException {
    int nread = 0;
    long totalRead = 0;
    DFSInputStream dfstm = null;
    if (stm.getWrappedStream() instanceof DFSInputStream) {
        dfstm = (DFSInputStream) (stm.getWrappedStream());
        totalRead = dfstm.getReadStatistics().getTotalBytesRead();
    }
    while (nread < length) {
        int nbytes = stm.read(position + nread, buffer, offset + nread, length - nread);
        replacedertTrue("Error in pread", nbytes > 0);
        nread += nbytes;
    }
    if (dfstm != null) {
        if (isHedgedRead) {
            replacedertTrue("Expected read statistic to be incremented", length <= dfstm.getReadStatistics().getTotalBytesRead() - totalRead);
        } else {
            replacedertEquals("Expected read statistic to be incremented", length, dfstm.getReadStatistics().getTotalBytesRead() - totalRead);
        }
    }
}

19 View Complete Implementation : TestReadAndSeekPageBlobAfterWrite.java
Copyright Apache License 2.0
Author : aliyun-beta
/**
 * Read "size" bytes of data and verify that what was read and what was written
 * are the same.
 */
private void readRandomDataAndVerify(int size) throws AzureException, IOException {
    byte[] b = new byte[size];
    FSDataInputStream stream = fs.open(PATH);
    int bytesRead = stream.read(b);
    stream.close();
    replacedertEquals(bytesRead, size);
    // compare the data read to the data written
    replacedertTrue(comparePrefix(randomData, b, size));
}

19 View Complete Implementation : TestHadoopArchives.java
Copyright Apache License 2.0
Author : apache
private static byte[] readAllWithRead4(FSDataInputStream fsdis, boolean close) throws IOException {
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final byte[] buffer = new byte[17];
        int totalRead = 0;
        int read;
        while (true) {
            read = fsdis.read(totalRead, buffer, 0, buffer.length);
            if (read > 0) {
                totalRead += read;
                baos.write(buffer, 0, read);
            } else if (read < 0) {
                // EOF
                break;
            } else {
                // read == 0:
                // zero result may be returned *only* in case if the 4th
                // parameter is 0. Since in our case this is 'buffer.length',
                // zero return value clearly indicates a bug:
                throw new replacedertionError("FSDataInputStream#read(4) returned 0, while " + " the 4th method parameter is " + buffer.length + ".");
            }
        }
        final byte[] result = baos.toByteArray();
        return result;
    } finally {
        if (close) {
            fsdis.close();
        }
    }
}

19 View Complete Implementation : TestFileSystemOperationExceptionHandling.java
Copyright Apache License 2.0
Author : aliyun-beta
public clreplaced TestFileSystemOperationExceptionHandling extends NativeAzureFileSystemBaseTest {

    FSDataInputStream inputStream = null;

    /*
   * Helper method to create a PageBlob test storage account.
   */
    private AzureBlobStorageTestAccount getPageBlobTestStorageAccount() throws Exception {
        Configuration conf = new Configuration();
        // Configure the page blob directories key so every file created is a page blob.
        conf.set(AzureNativeFileSystemStore.KEY_PAGE_BLOB_DIRECTORIES, "/");
        // Configure the atomic rename directories key so every folder will have
        // atomic rename applied.
        conf.set(AzureNativeFileSystemStore.KEY_ATOMIC_RENAME_DIRECTORIES, "/");
        return AzureBlobStorageTestAccount.create(conf);
    }

    /*
   * Helper method that creates a InputStream to validate exceptions
   * for various scenarios
   */
    private void setupInputStreamToTest(AzureBlobStorageTestAccount testAccount) throws Exception {
        fs = testAccount.getFileSystem();
        // Step 1: Create a file and write dummy data.
        Path testFilePath1 = new Path("test1.dat");
        Path testFilePath2 = new Path("test2.dat");
        FSDataOutputStream outputStream = fs.create(testFilePath1);
        String testString = "This is a test string";
        outputStream.write(testString.getBytes());
        outputStream.close();
        // Step 2: Open a read stream on the file.
        inputStream = fs.open(testFilePath1);
        // Step 3: Rename the file
        fs.rename(testFilePath1, testFilePath2);
    }

    /*
   * Tests a basic single threaded read scenario for Page blobs.
   */
    @Test(expected = FileNotFoundException.clreplaced)
    public void testSingleThreadedPageBlobReadScenario() throws Throwable {
        AzureBlobStorageTestAccount testAccount = getPageBlobTestStorageAccount();
        setupInputStreamToTest(testAccount);
        byte[] readBuffer = new byte[512];
        inputStream.read(readBuffer);
    }

    /*
   * Tests a basic single threaded seek scenario for Page blobs.
   */
    @Test(expected = FileNotFoundException.clreplaced)
    public void testSingleThreadedPageBlobSeekScenario() throws Throwable {
        AzureBlobStorageTestAccount testAccount = getPageBlobTestStorageAccount();
        setupInputStreamToTest(testAccount);
        inputStream.seek(5);
    }

    /*
   * Test a basic single thread seek scenario for Block blobs.
   */
    @Test(expected = FileNotFoundException.clreplaced)
    public void testSingleThreadBlockBlobSeekScenario() throws Throwable {
        AzureBlobStorageTestAccount testAccount = createTestAccount();
        setupInputStreamToTest(testAccount);
        inputStream.seek(5);
    }

    /*
   * Tests a basic single threaded read scenario for Block blobs.
   */
    @Test(expected = FileNotFoundException.clreplaced)
    public void testSingledThreadBlockBlobReadScenario() throws Throwable {
        AzureBlobStorageTestAccount testAccount = createTestAccount();
        setupInputStreamToTest(testAccount);
        byte[] readBuffer = new byte[512];
        inputStream.read(readBuffer);
    }

    @After
    public void tearDown() throws Exception {
        if (inputStream != null) {
            inputStream.close();
        }
    }

    @Override
    protected AzureBlobStorageTestAccount createTestAccount() throws Exception {
        return AzureBlobStorageTestAccount.create();
    }
}

19 View Complete Implementation : TestRpcProgramNfs3.java
Copyright Apache License 2.0
Author : apache
private byte[] getFileContentsUsingDfs(String fileName, int len) throws Exception {
    final FSDataInputStream in = hdfs.open(new Path(fileName));
    final byte[] ret = new byte[len];
    in.readFully(ret);
    try {
        in.readByte();
        replacedert.fail("expected end of file");
    } catch (EOFException e) {
    // expected. Unfortunately there is no replacedociated message to check
    }
    in.close();
    return ret;
}

19 View Complete Implementation : ITestAzureHugeFiles.java
Copyright Apache License 2.0
Author : apache
protected FSDataInputStream openDataFile() throws IOException {
    NanoTimer openTimer = new NanoTimer();
    FSDataInputStream inputStream = getFileSystem().open(hugefile, UPLOAD_BLOCKSIZE);
    openTimer.end("open data file");
    return inputStream;
}

19 View Complete Implementation : TestHadoopArchives.java
Copyright Apache License 2.0
Author : apache
private static void expectSeekIOE(FSDataInputStream fsdis, long seekPos, String message) {
    try {
        fsdis.seek(seekPos);
        replacedertTrue(message + " (Position = " + fsdis.getPos() + ")", false);
    } catch (IOException ioe) {
    // okay
    }
}

19 View Complete Implementation : AzureTestUtils.java
Copyright Apache License 2.0
Author : apache
/**
 * Read string from stream.
 */
public static String readStringFromStream(FSDataInputStream inputStream) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    final int BUFFER_SIZE = 1024;
    char[] buffer = new char[BUFFER_SIZE];
    int count = reader.read(buffer, 0, BUFFER_SIZE);
    if (count > BUFFER_SIZE) {
        throw new IOException("Exceeded buffer size");
    }
    inputStream.close();
    return new String(buffer, 0, count);
}

19 View Complete Implementation : BoundedRangeFileInputStream.java
Copyright Apache License 2.0
Author : apache
/**
 * BoundedRangeFIleInputStream abstracts a contiguous region of a Hadoop
 * FSDataInputStream as a regular input stream. One can create multiple
 * BoundedRangeFileInputStream on top of the same FSDataInputStream and they
 * would not interfere with each other.
 */
public clreplaced BoundedRangeFileInputStream extends InputStream {

    private FSDataInputStream in;

    private long pos;

    private long end;

    private long mark;

    private final byte[] oneByte = new byte[1];

    /**
     * Constructor
     *
     * @param in
     *          The FSDataInputStream we connect to.
     * @param offset
     *          Beginning offset of the region.
     * @param length
     *          Length of the region.
     *
     *          The actual length of the region may be smaller if (off_begin +
     *          length) goes beyond the end of FS input stream.
     */
    public BoundedRangeFileInputStream(FSDataInputStream in, long offset, long length) {
        if (offset < 0 || length < 0) {
            throw new IndexOutOfBoundsException("Invalid offset/length: " + offset + "/" + length);
        }
        this.in = in;
        this.pos = offset;
        this.end = offset + length;
        this.mark = -1;
    }

    @Override
    public int available() throws IOException {
        int avail = in.available();
        if (pos + avail > end) {
            avail = (int) (end - pos);
        }
        return avail;
    }

    @Override
    public int read() throws IOException {
        int ret = read(oneByte);
        if (ret == 1)
            return oneByte[0] & 0xff;
        return -1;
    }

    @Override
    public int read(byte[] b) throws IOException {
        return read(b, 0, b.length);
    }

    @Override
    public int read(byte[] b, int off, int len) throws IOException {
        if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
            throw new IndexOutOfBoundsException();
        }
        int n = (int) Math.min(Integer.MAX_VALUE, Math.min(len, (end - pos)));
        if (n == 0)
            return -1;
        int ret = 0;
        synchronized (in) {
            in.seek(pos);
            ret = in.read(b, off, n);
        }
        if (ret < 0) {
            end = pos;
            return -1;
        }
        pos += ret;
        return ret;
    }

    @Override
    public /*
   * We may skip beyond the end of the file.
   */
    long skip(long n) throws IOException {
        long len = Math.min(n, end - pos);
        pos += len;
        return len;
    }

    @Override
    public synchronized void mark(int readlimit) {
        mark = pos;
    }

    @Override
    public synchronized void reset() throws IOException {
        if (mark < 0)
            throw new IOException("Resetting to invalid mark");
        pos = mark;
    }

    @Override
    public boolean markSupported() {
        return true;
    }

    @Override
    public void close() {
        // Invalidate the state of the stream.
        in = null;
        pos = end;
        mark = -1;
    }
}

19 View Complete Implementation : AbstractContractOpenTest.java
Copyright Apache License 2.0
Author : apache
/**
 * Test Open operations.
 */
public abstract clreplaced AbstractContractOpenTest extends AbstractFSContractTestBase {

    private FSDataInputStream instream;

    @Override
    protected Configuration createConfiguration() {
        Configuration conf = super.createConfiguration();
        conf.setInt(CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_KEY, 4096);
        return conf;
    }

    @Override
    public void teardown() throws Exception {
        IOUtils.closeStream(instream);
        instream = null;
        super.teardown();
    }

    @Test
    public void testOpenReadZeroByteFile() throws Throwable {
        describe("create & read a 0 byte file");
        Path path = path("zero.txt");
        touch(getFileSystem(), path);
        instream = getFileSystem().open(path);
        replacedertEquals(0, instream.getPos());
        // expect initial read to fail
        replacedertMinusOne("initial byte read", instream.read());
    }

    @Test
    public void testFsIsEncrypted() throws Exception {
        describe("create an empty file and call FileStatus.isEncrypted()");
        final Path path = path("file");
        createFile(getFileSystem(), path, false, new byte[0]);
        final FileStatus stat = getFileSystem().getFileStatus(path);
        replacedertEquals("Result wrong for for isEncrypted() in " + stat, areZeroByteFilesEncrypted(), stat.isEncrypted());
    }

    /**
     * Are zero byte files encrypted. This is implicitly
     * false for filesystems which do not encrypt.
     * @return true iff zero byte files are encrypted.
     */
    protected boolean areZeroByteFilesEncrypted() {
        return false;
    }

    @Test
    public void testOpenReadDir() throws Throwable {
        describe("create & read a directory");
        Path path = path("zero.dir");
        mkdirs(path);
        try {
            instream = getFileSystem().open(path);
            // at this point we've opened a directory
            fail("A directory has been opened for reading");
        } catch (FileNotFoundException e) {
            handleExpectedException(e);
        } catch (IOException e) {
            handleRelaxedException("opening a directory for reading", "FileNotFoundException", e);
        }
    }

    @Test
    public void testOpenReadDirWithChild() throws Throwable {
        describe("create & read a directory which has a child");
        Path path = path("zero.dir");
        mkdirs(path);
        Path path2 = new Path(path, "child");
        mkdirs(path2);
        try {
            instream = getFileSystem().open(path);
            // at this point we've opened a directory
            fail("A directory has been opened for reading");
        } catch (FileNotFoundException e) {
            handleExpectedException(e);
        } catch (IOException e) {
            handleRelaxedException("opening a directory for reading", "FileNotFoundException", e);
        }
    }

    @Test
    public void testOpenFileTwice() throws Throwable {
        describe("verify that two opened file streams are independent");
        Path path = path("testopenfiletwice.txt");
        byte[] block = dataset(TEST_FILE_LEN, 0, 255);
        // this file now has a simple rule: offset => value
        createFile(getFileSystem(), path, true, block);
        // open first
        FSDataInputStream instream1 = getFileSystem().open(path);
        FSDataInputStream instream2 = null;
        try {
            int c = instream1.read();
            replacedertEquals(0, c);
            instream2 = getFileSystem().open(path);
            replacedertEquals("first read of instream 2", 0, instream2.read());
            replacedertEquals("second read of instream 1", 1, instream1.read());
            instream1.close();
            replacedertEquals("second read of instream 2", 1, instream2.read());
            // close instream1 again
            instream1.close();
        } finally {
            IOUtils.closeStream(instream1);
            IOUtils.closeStream(instream2);
        }
    }

    @Test
    public void testSequentialRead() throws Throwable {
        describe("verify that sequential read() operations return values");
        Path path = path("testsequentialread.txt");
        int len = 4;
        // 64
        int base = 0x40;
        byte[] block = dataset(len, base, base + len);
        // this file now has a simple rule: offset => (value | 0x40)
        createFile(getFileSystem(), path, true, block);
        // open first
        instream = getFileSystem().open(path);
        replacedertEquals(base, instream.read());
        replacedertEquals(base + 1, instream.read());
        replacedertEquals(base + 2, instream.read());
        replacedertEquals(base + 3, instream.read());
        // and now, failures
        replacedertEquals(-1, instream.read());
        replacedertEquals(-1, instream.read());
        instream.close();
    }

    @Test
    public void testOpenFileReadZeroByte() throws Throwable {
        describe("create & read a 0 byte file through the builders");
        Path path = path("zero.txt");
        FileSystem fs = getFileSystem();
        fs.createFile(path).overwrite(true).build().close();
        try (FSDataInputStream is = fs.openFile(path).opt("fs.test.something", true).opt("fs.test.something2", 3).opt("fs.test.something3", "3").build().get()) {
            replacedertMinusOne("initial byte read", is.read());
        }
    }

    @Test
    public void testOpenFileUnknownOption() throws Throwable {
        describe("calling openFile fails when a 'must()' option is unknown");
        FutureDataInputStreamBuilder builder = getFileSystem().openFile(path("testOpenFileUnknownOption")).opt("fs.test.something", true).must("fs.test.something", true);
        intercept(IllegalArgumentException.clreplaced, () -> builder.build());
    }

    @Test
    public void testOpenFileLazyFail() throws Throwable {
        describe("openFile fails on a missing file in the get() and not before");
        FutureDataInputStreamBuilder builder = getFileSystem().openFile(path("testOpenFileLazyFail")).opt("fs.test.something", true);
        interceptFuture(FileNotFoundException.clreplaced, "", builder.build());
    }

    @Test
    public void testOpenFileFailExceptionally() throws Throwable {
        describe("openFile missing file chains into exceptionally()");
        FutureDataInputStreamBuilder builder = getFileSystem().openFile(path("testOpenFileFailExceptionally")).opt("fs.test.something", true);
        replacedertNull("exceptional uprating", builder.build().exceptionally(ex -> null).get());
    }

    @Test
    public void testAwaitFutureFailToFNFE() throws Throwable {
        describe("Verify that FutureIOSupport.awaitFuture extracts IOExceptions");
        FutureDataInputStreamBuilder builder = getFileSystem().openFile(path("testAwaitFutureFailToFNFE")).opt("fs.test.something", true);
        intercept(FileNotFoundException.clreplaced, () -> FutureIOSupport.awaitFuture(builder.build()));
    }

    @Test
    public void testAwaitFutureTimeoutFailToFNFE() throws Throwable {
        describe("Verify that FutureIOSupport.awaitFuture with a timeout works");
        FutureDataInputStreamBuilder builder = getFileSystem().openFile(path("testAwaitFutureFailToFNFE")).opt("fs.test.something", true);
        intercept(FileNotFoundException.clreplaced, () -> FutureIOSupport.awaitFuture(builder.build(), 10, TimeUnit.DAYS));
    }

    @Test
    public void testOpenFileExceptionallyTranslating() throws Throwable {
        describe("openFile missing file chains into exceptionally()");
        CompletableFuture<FSDataInputStream> f = getFileSystem().openFile(path("testOpenFileUnknownOption")).build();
        interceptFuture(RuntimeException.clreplaced, "exceptionally", f.exceptionally(ex -> {
            throw new RuntimeException("exceptionally", ex);
        }));
    }

    @Test
    public void testChainedFailureAwaitFuture() throws Throwable {
        describe("await Future handles chained failures");
        CompletableFuture<FSDataInputStream> f = getFileSystem().openFile(path("testOpenFileUnknownOption")).build();
        intercept(RuntimeException.clreplaced, "exceptionally", () -> FutureIOSupport.awaitFuture(f.exceptionally(ex -> {
            throw new RuntimeException("exceptionally", ex);
        })));
    }

    @Test
    public void testOpenFileApplyRead() throws Throwable {
        describe("use the apply sequence to read a whole file");
        Path path = path("testOpenFileApplyRead");
        FileSystem fs = getFileSystem();
        int len = 4096;
        createFile(fs, path, true, dataset(len, 0x40, 0x80));
        CompletableFuture<Long> readAllBytes = fs.openFile(path).withFileStatus(fs.getFileStatus(path)).build().thenApply(ContractTestUtils::readStream);
        replacedertEquals("Wrong number of bytes read value", len, (long) readAllBytes.get());
    }

    @Test
    public void testOpenFileApplyAsyncRead() throws Throwable {
        describe("verify that async accept callbacks are evaluated");
        Path path = path("testOpenFileApplyAsyncRead");
        FileSystem fs = getFileSystem();
        createFile(fs, path, true, dataset(4, 0x40, 0x80));
        CompletableFuture<FSDataInputStream> future = fs.openFile(path).build();
        AtomicBoolean accepted = new AtomicBoolean(false);
        future.thenAcceptAsync(i -> accepted.set(true)).get();
        replacedertTrue("async accept operation not invoked", accepted.get());
    }

    @Test
    public void testOpenFileNullStatus() throws Throwable {
        describe("use openFile() with a null status");
        Path path = path("testOpenFileNullStatus");
        intercept(NullPointerException.clreplaced, () -> getFileSystem().openFile(path).withFileStatus(null));
    }
}

19 View Complete Implementation : DFSClientCache.java
Copyright Apache License 2.0
Author : aliyun-beta
FSDataInputStream getDfsInputStream(String userName, String inodePath) {
    DFSInputStreamCaheKey k = new DFSInputStreamCaheKey(userName, inodePath);
    FSDataInputStream s = null;
    try {
        s = inputstreamCache.get(k);
    } catch (ExecutionException e) {
        LOG.warn("Failed to create DFSInputStream for user:" + userName + " Cause:" + e);
    }
    return s;
}

19 View Complete Implementation : TestBlockTokenWithDFS.java
Copyright Apache License 2.0
Author : aliyun-beta
// read a file using blockSeekTo()
private boolean checkFile1(FSDataInputStream in, byte[] expected) {
    byte[] toRead = new byte[expected.length];
    int totalRead = 0;
    int nRead = 0;
    try {
        while ((nRead = in.read(toRead, totalRead, toRead.length - totalRead)) > 0) {
            totalRead += nRead;
        }
    } catch (IOException e) {
        return false;
    }
    replacedertEquals("Cannot read file.", toRead.length, totalRead);
    return checkFile(toRead, expected);
}

19 View Complete Implementation : TestHadoopArchives.java
Copyright Apache License 2.0
Author : aliyun-beta
private static byte[] readAllWithReadFully(int totalLength, FSDataInputStream fsdis, boolean close) throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // Simulate reading of some data structures of known length:
    final byte[] buffer = new byte[17];
    final int times = totalLength / buffer.length;
    final int remainder = totalLength % buffer.length;
    // it would be simpler to leave the position tracking to the
    // InputStream, but we need to check the methods #readFully(2)
    // and #readFully(4) that receive the position as a parameter:
    int position = 0;
    try {
        // read "data structures":
        for (int i = 0; i < times; i++) {
            fsdis.readFully(position, buffer);
            position += buffer.length;
            baos.write(buffer);
        }
        if (remainder > 0) {
            // read the remainder:
            fsdis.readFully(position, buffer, 0, remainder);
            position += remainder;
            baos.write(buffer, 0, remainder);
        }
        try {
            fsdis.readFully(position, buffer, 0, 1);
            replacedertTrue(false);
        } catch (IOException ioe) {
        // okay
        }
        replacedertEquals(totalLength, position);
        final byte[] result = baos.toByteArray();
        replacedertEquals(totalLength, result.length);
        return result;
    } finally {
        if (close) {
            fsdis.close();
        }
    }
}

19 View Complete Implementation : ITestNativeAzureFileSystemAppend.java
Copyright Apache License 2.0
Author : apache
/*
   * Helper method to verify a file data equal to "dataLength" parameter
   */
private boolean verifyFileData(int dataLength, byte[] testData, int testDataIndex, FSDataInputStream srcStream) {
    try {
        byte[] fileBuffer = new byte[dataLength];
        byte[] testDataBuffer = new byte[dataLength];
        int fileBytesRead = srcStream.read(fileBuffer);
        if (fileBytesRead < dataLength) {
            return false;
        }
        System.arraycopy(testData, testDataIndex, testDataBuffer, 0, dataLength);
        if (!Arrays.equals(fileBuffer, testDataBuffer)) {
            return false;
        }
        return true;
    } catch (Exception ex) {
        return false;
    }
}

19 View Complete Implementation : TestFileCreation.java
Copyright Apache License 2.0
Author : aliyun-beta
private byte[] readAll(FSDataInputStream in) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int n = 0;
    while ((n = in.read(buffer)) > -1) {
        out.write(buffer, 0, n);
    }
    return out.toByteArray();
}

19 View Complete Implementation : StripedFileTestUtil.java
Copyright Apache License 2.0
Author : aliyun-beta
static void replacedertSeekAndRead(FSDataInputStream fsdis, int pos, int writeBytes) throws IOException {
    fsdis.seek(pos);
    byte[] buf = new byte[writeBytes];
    int readLen = StripedFileTestUtil.readAll(fsdis, buf);
    replacedertEquals(readLen, writeBytes - pos);
    for (int i = 0; i < readLen; i++) {
        replacedertEquals("Byte at " + i + " should be the same", StripedFileTestUtil.getByte(pos + i), buf[i]);
    }
}

19 View Complete Implementation : TestEncryptedTransfer.java
Copyright Apache License 2.0
Author : apache
@Test
public void testEncryptedAppendRequiringBlockTransfer() throws IOException {
    setEncryptionConfigKeys();
    // start up 4 DNs
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
    fs = getFileSystem(conf);
    // Create a file with replication 3, so its block is on 3 / 4 DNs.
    writeTestDataToFile(fs);
    replacedertEquals(PLAIN_TEXT, DFSTestUtil.readFile(fs, TEST_PATH));
    // Shut down one of the DNs holding a block replica.
    FSDataInputStream in = fs.open(TEST_PATH);
    List<LocatedBlock> locatedBlocks = DFSTestUtil.getAllBlocks(in);
    in.close();
    replacedertEquals(1, locatedBlocks.size());
    replacedertEquals(3, locatedBlocks.get(0).getLocations().length);
    DataNode dn = cluster.getDataNode(locatedBlocks.get(0).getLocations()[0].getIpcPort());
    dn.shutdown();
    // Reopen the file for append, which will need to add another DN to the
    // pipeline and in doing so trigger a block transfer.
    writeTestDataToFile(fs);
    replacedertEquals(PLAIN_TEXT + PLAIN_TEXT, DFSTestUtil.readFile(fs, TEST_PATH));
}

19 View Complete Implementation : S3AScaleTestBase.java
Copyright Apache License 2.0
Author : apache
/**
 * Get the inner stream of an input stream.
 * Raises an exception if the inner stream is not an S3A input stream
 * @param in wrapper
 * @return the inner stream
 * @throws replacedertionError if the inner stream is of the wrong type
 */
protected S3AInputStream getS3AInputStream(FSDataInputStream in) {
    InputStream inner = in.getWrappedStream();
    if (inner instanceof S3AInputStream) {
        return (S3AInputStream) inner;
    } else {
        throw new replacedertionError("Not an S3AInputStream: " + inner);
    }
}

19 View Complete Implementation : TestBlockTokenWithDFS.java
Copyright Apache License 2.0
Author : apache
// read a file using blockSeekTo()
private boolean checkFile1(FSDataInputStream in, byte[] expected) {
    byte[] toRead = new byte[expected.length];
    int totalRead = 0;
    int nRead = 0;
    try {
        while ((nRead = in.read(toRead, totalRead, toRead.length - totalRead)) > 0) {
            totalRead += nRead;
        }
    } catch (IOException e) {
        return false;
    }
    replacedertEquals("Cannot read file.", toRead.length, totalRead);
    return checkFile(toRead, expected);
}

19 View Complete Implementation : DFSClientCache.java
Copyright Apache License 2.0
Author : apache
FSDataInputStream getDfsInputStream(String userName, String inodePath, int namenodeId) {
    DFSInputStreamCacheKey k = new DFSInputStreamCacheKey(userName, inodePath, namenodeId);
    FSDataInputStream s = null;
    try {
        s = inputstreamCache.get(k);
    } catch (ExecutionException e) {
        LOG.warn("Failed to create DFSInputStream for user: {}", userName, e);
    }
    return s;
}

19 View Complete Implementation : ITestBlockBlobInputStream.java
Copyright Apache License 2.0
Author : apache
private void verifyConsistentReads(FSDataInputStream inputStreamV1, FSDataInputStream inputStreamV2, byte[] bufferV1, byte[] bufferV2) throws IOException {
    int size = bufferV1.length;
    final int numBytesReadV1 = inputStreamV1.read(bufferV1, 0, size);
    replacedertEquals("Bytes read from V1 stream", size, numBytesReadV1);
    final int numBytesReadV2 = inputStreamV2.read(bufferV2, 0, size);
    replacedertEquals("Bytes read from V2 stream", size, numBytesReadV2);
    replacedertArrayEquals("Mismatch in read data", bufferV1, bufferV2);
}

19 View Complete Implementation : S3AScaleTestBase.java
Copyright Apache License 2.0
Author : apache
/**
 * Get the input stream statistics of an input stream.
 * Raises an exception if the inner stream is not an S3A input stream
 * @param in wrapper
 * @return the statistics for the inner stream
 */
protected S3AInstrumentation.InputStreamStatistics getInputStreamStatistics(FSDataInputStream in) {
    return getS3AInputStream(in).getS3AStreamStatistics();
}

19 View Complete Implementation : TestHadoopArchives.java
Copyright Apache License 2.0
Author : apache
private static byte[] readAllWithReadFully(int totalLength, FSDataInputStream fsdis, boolean close) throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // Simulate reading of some data structures of known length:
    final byte[] buffer = new byte[17];
    final int times = totalLength / buffer.length;
    final int remainder = totalLength % buffer.length;
    // it would be simpler to leave the position tracking to the
    // InputStream, but we need to check the methods #readFully(2)
    // and #readFully(4) that receive the position as a parameter:
    int position = 0;
    try {
        // read "data structures":
        for (int i = 0; i < times; i++) {
            fsdis.readFully(position, buffer);
            position += buffer.length;
            baos.write(buffer);
        }
        if (remainder > 0) {
            // read the remainder:
            fsdis.readFully(position, buffer, 0, remainder);
            position += remainder;
            baos.write(buffer, 0, remainder);
        }
        try {
            fsdis.readFully(position, buffer, 0, 1);
            replacedertTrue(false);
        } catch (IOException ioe) {
        // okay
        }
        replacedertEquals(totalLength, position);
        final byte[] result = baos.toByteArray();
        replacedertEquals(totalLength, result.length);
        return result;
    } finally {
        if (close) {
            fsdis.close();
        }
    }
}

19 View Complete Implementation : ITestS3AUnbuffer.java
Copyright Apache License 2.0
Author : apache
private boolean isObjectStreamOpen(FSDataInputStream inputStream) {
    return ((S3AInputStream) inputStream.getWrappedStream()).isObjectStreamOpen();
}

19 View Complete Implementation : TestRpcProgramNfs3.java
Copyright Apache License 2.0
Author : aliyun-beta
private byte[] getFileContentsUsingDfs(String fileName, int len) throws Exception {
    final FSDataInputStream in = hdfs.open(new Path(fileName));
    final byte[] ret = new byte[len];
    in.readFully(ret);
    try {
        in.readByte();
        replacedert.fail("expected end of file");
    } catch (EOFException e) {
    // expected. Unfortunately there is no replacedociated message to check
    }
    in.close();
    return ret;
}

19 View Complete Implementation : AbstractS3SelectTest.java
Copyright Apache License 2.0
Author : apache
/**
 * Parse a selection to lines; log at info.
 * @param selection selection input
 * @return a list of lines.
 * @throws IOException if raised during the read.
 */
protected List<String> parseToLines(final FSDataInputStream selection) throws IOException {
    return parseToLines(selection, getMaxLines());
}

19 View Complete Implementation : TestHadoopArchives.java
Copyright Apache License 2.0
Author : aliyun-beta
private static byte[] readAllWithRead4(FSDataInputStream fsdis, boolean close) throws IOException {
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final byte[] buffer = new byte[17];
        int totalRead = 0;
        int read;
        while (true) {
            read = fsdis.read(totalRead, buffer, 0, buffer.length);
            if (read > 0) {
                totalRead += read;
                baos.write(buffer, 0, read);
            } else if (read < 0) {
                // EOF
                break;
            } else {
                // read == 0:
                // zero result may be returned *only* in case if the 4th
                // parameter is 0. Since in our case this is 'buffer.length',
                // zero return value clearly indicates a bug:
                throw new replacedertionError("FSDataInputStream#read(4) returned 0, while " + " the 4th method parameter is " + buffer.length + ".");
            }
        }
        final byte[] result = baos.toByteArray();
        return result;
    } finally {
        if (close) {
            fsdis.close();
        }
    }
}

19 View Complete Implementation : StripedFileTestUtil.java
Copyright Apache License 2.0
Author : aliyun-beta
static int readAll(FSDataInputStream in, byte[] buf) throws IOException {
    int readLen = 0;
    int ret;
    while ((ret = in.read(buf, readLen, buf.length - readLen)) >= 0 && readLen <= buf.length) {
        readLen += ret;
    }
    return readLen;
}

19 View Complete Implementation : ITestPageBlobInputStream.java
Copyright Apache License 2.0
Author : apache
/**
 * Validates the implementation of InputStream.skip and ensures there is no
 * network I/O for version 1 of the block blob input stream.
 * @throws Exception
 */
@Test
public void test_0307_SkipBounds() throws Exception {
    replacedumeHugeFileExists();
    try (FSDataInputStream inputStream = fs.open(TEST_FILE_PATH)) {
        long skipped = inputStream.skip(-1);
        replacedertEquals(0, skipped);
        skipped = inputStream.skip(0);
        replacedertEquals(0, skipped);
        replacedertTrue(testFileLength > 0);
        skipped = inputStream.skip(testFileLength);
        replacedertEquals(testFileLength, skipped);
        intercept(EOFException.clreplaced, new Callable<Long>() {

            @Override
            public Long call() throws Exception {
                return inputStream.skip(1);
            }
        });
    }
}

19 View Complete Implementation : StripedFileTestUtil.java
Copyright Apache License 2.0
Author : apache
static void replacedertSeekAndRead(FSDataInputStream fsdis, int pos, int writeBytes) throws IOException {
    fsdis.seek(pos);
    byte[] buf = new byte[writeBytes - pos];
    IOUtils.readFully(fsdis, buf, 0, buf.length);
    for (int i = 0; i < buf.length; i++) {
        replacedertEquals("Byte at " + i + " should be the same", StripedFileTestUtil.getByte(pos + i), buf[i]);
    }
}

18 View Complete Implementation : ITestOutputStreamSemantics.java
Copyright Apache License 2.0
Author : apache
private void validate(Path path, byte[] writeBuffer, boolean isEqual) throws IOException {
    String blobPath = path.toUri().getPath();
    try (FSDataInputStream inputStream = fs.open(path)) {
        byte[] readBuffer = new byte[PageBlobFormatHelpers.PAGE_SIZE - PageBlobFormatHelpers.PAGE_HEADER_SIZE];
        int numBytesRead = inputStream.read(readBuffer, 0, readBuffer.length);
        if (isEqual) {
            replacedertArrayEquals(String.format("Bytes read do not match bytes written to %1$s", blobPath), writeBuffer, readBuffer);
        } else {
            replacedertThat(String.format("Bytes read unexpectedly match bytes written to %1$s", blobPath), readBuffer, IsNot.not(IsEqual.equalTo(writeBuffer)));
        }
    }
}

18 View Complete Implementation : ITestAzureBlobFileSystemCopy.java
Copyright Apache License 2.0
Author : apache
private String readString(FSDataInputStream inputStream) throws IOException {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
        final int bufferSize = 1024;
        char[] buffer = new char[bufferSize];
        int count = reader.read(buffer, 0, bufferSize);
        if (count > bufferSize) {
            throw new IOException("Exceeded buffer size");
        }
        return new String(buffer, 0, count);
    }
}

18 View Complete Implementation : ITestBlockBlobInputStream.java
Copyright Apache License 2.0
Author : apache
private void validateSkipBounds(FileSystem fs) throws Exception {
    replacedumeHugeFileExists();
    try (FSDataInputStream inputStream = fs.open(TEST_FILE_PATH)) {
        NanoTimer timer = new NanoTimer();
        long skipped = inputStream.skip(-1);
        replacedertEquals(0, skipped);
        skipped = inputStream.skip(0);
        replacedertEquals(0, skipped);
        replacedertTrue(testFileLength > 0);
        skipped = inputStream.skip(testFileLength);
        replacedertEquals(testFileLength, skipped);
        intercept(EOFException.clreplaced, new Callable<Long>() {

            @Override
            public Long call() throws Exception {
                return inputStream.skip(1);
            }
        });
        long elapsedTimeMs = timer.elapsedTimeMs();
        replacedertTrue(String.format("There should not be any network I/O (elapsedTimeMs=%1$d).", elapsedTimeMs), elapsedTimeMs < 20);
    }
}

18 View Complete Implementation : ITestS3Select.java
Copyright Apache License 2.0
Author : apache
/**
 * Validate the abort logic.
 */
@Test
public void testCloseWithAbort() throws Throwable {
    describe("Close the stream with the readahead outstanding");
    S3ATestUtils.MetricDiff readOps = new S3ATestUtils.MetricDiff(getFileSystem(), Statistic.STREAM_READ_OPERATIONS_INCOMPLETE);
    selectConf.setInt(READAHEAD_RANGE, 2);
    FSDataInputStream stream = select(getFileSystem(), csvPath, selectConf, "SELECT * FROM S3OBJECT s");
    SelectInputStream sis = (SelectInputStream) stream.getWrappedStream();
    replacedertEquals("Readahead on " + sis, 2, sis.getReadahead());
    stream.setReadahead(1L);
    replacedertEquals("Readahead on " + sis, 1, sis.getReadahead());
    stream.read();
    S3AInstrumentation.InputStreamStatistics stats = sis.getS3AStreamStatistics();
    replacedertEquals("Read count in " + sis, 1, stats.bytesRead);
    stream.close();
    replacedertEquals("Abort count in " + sis, 1, stats.aborted);
    readOps.replacedertDiffEquals("Read operations are still considered active", 0);
    intercept(PathIOException.clreplaced, FSExceptionMessages.STREAM_IS_CLOSED, () -> stream.read());
}

18 View Complete Implementation : ITestS3Select.java
Copyright Apache License 2.0
Author : apache
/**
 * This is an expanded example for the doreplacedentation.
 * Also helps catch out unplanned changes to the configuration strings.
 */
@Test
public void testSelectFileExample() throws Throwable {
    describe("Select the entire file, expect all rows but the header");
    int len = (int) getFileSystem().getFileStatus(csvPath).getLen();
    FutureDataInputStreamBuilder builder = getFileSystem().openFile(csvPath).must("fs.s3a.select.sql", SELECT_ODD_ENTRIES).must("fs.s3a.select.input.format", "CSV").must("fs.s3a.select.input.compression", "NONE").must("fs.s3a.select.input.csv.header", "use").must("fs.s3a.select.output.format", "CSV");
    CompletableFuture<FSDataInputStream> future = builder.build();
    try (FSDataInputStream select = future.get()) {
        // process the output
        byte[] bytes = new byte[len];
        int actual = select.read(bytes);
        LOG.info("file length is {}; length of selected data is {}", len, actual);
    }
}

18 View Complete Implementation : FileSystemRMStateStore.java
Copyright Apache License 2.0
Author : apache
private byte[] readFile(Path inputPath, long len) throws Exception {
    FSDataInputStream fsIn = null;
    try {
        fsIn = fs.open(inputPath);
        // state data will not be that "long"
        byte[] data = new byte[(int) len];
        fsIn.readFully(data);
        return data;
    } finally {
        IOUtils.cleanupWithLogger(LOG, fsIn);
    }
}

18 View Complete Implementation : AbstractContractSeekTest.java
Copyright Apache License 2.0
Author : apache
@Test
public void testReadNullBuffer() throws Throwable {
    describe("try to read a null buffer ");
    replacedumeSupportsPositionedReadable();
    try (FSDataInputStream in = getFileSystem().open(smallSeekFile)) {
        // Null buffer
        int r = in.read(0, null, 0, 16);
        fail("Expected an exception from a read into a null buffer, got " + r);
    } catch (IllegalArgumentException e) {
    // expected
    }
}

18 View Complete Implementation : ITestPageBlobInputStream.java
Copyright Apache License 2.0
Author : apache
/**
 * Validates the implementation of InputStream.markSupported.
 * @throws IOException
 */
@Test
public void test_0301_MarkSupported() throws IOException {
    replacedumeHugeFileExists();
    try (FSDataInputStream inputStream = fs.open(TEST_FILE_PATH)) {
        replacedertTrue("mark is not supported", inputStream.markSupported());
    }
}

18 View Complete Implementation : ITestS3Select.java
Copyright Apache License 2.0
Author : apache
@Test
public void testCloseWithNoAbort() throws Throwable {
    describe("Close the stream with the readahead outstandingV");
    FSDataInputStream stream = select(getFileSystem(), csvPath, selectConf, "SELECT * FROM S3OBJECT s");
    stream.setReadahead(0x1000L);
    SelectInputStream sis = (SelectInputStream) stream.getWrappedStream();
    S3AInstrumentation.InputStreamStatistics stats = sis.getS3AStreamStatistics();
    stream.close();
    replacedertEquals("Close count in " + sis, 1, stats.closed);
    replacedertEquals("Abort count in " + sis, 0, stats.aborted);
    replacedertTrue("No bytes read in close of " + sis, stats.bytesReadInClose > 0);
}

18 View Complete Implementation : HistoryServerFileSystemStateStoreService.java
Copyright Apache License 2.0
Author : apache
private byte[] readFile(Path file, long numBytes) throws IOException {
    byte[] data = new byte[(int) numBytes];
    FSDataInputStream in = fs.open(file);
    try {
        in.readFully(data);
    } finally {
        IOUtils.cleanupWithLogger(LOG, in);
    }
    return data;
}

18 View Complete Implementation : ITestAzureBlobFileSystemRandomRead.java
Copyright Apache License 2.0
Author : apache
/**
 * Validates the implementation of InputStream.skip and ensures there is no
 * network I/O for AbfsInputStream
 * @throws Exception
 */
@Test
public void testSkipBounds() throws Exception {
    replacedumeHugeFileExists();
    try (FSDataInputStream inputStream = this.getFileSystem().open(TEST_FILE_PATH)) {
        ContractTestUtils.NanoTimer timer = new ContractTestUtils.NanoTimer();
        long skipped = inputStream.skip(-1);
        replacedertEquals(0, skipped);
        skipped = inputStream.skip(0);
        replacedertEquals(0, skipped);
        replacedertTrue(testFileLength > 0);
        skipped = inputStream.skip(testFileLength);
        replacedertEquals(testFileLength, skipped);
        intercept(EOFException.clreplaced, new Callable<Long>() {

            @Override
            public Long call() throws Exception {
                return inputStream.skip(1);
            }
        });
        long elapsedTimeMs = timer.elapsedTimeMs();
        replacedertTrue(String.format("There should not be any network I/O (elapsedTimeMs=%1$d).", elapsedTimeMs), elapsedTimeMs < MAX_ELAPSEDTIMEMS);
    }
}

18 View Complete Implementation : TestBlockTokenWithDFS.java
Copyright Apache License 2.0
Author : apache
// read a file using fetchBlockByteRange()
private boolean checkFile2(FSDataInputStream in, byte[] expected) {
    byte[] toRead = new byte[expected.length];
    try {
        replacedertEquals("Cannot read file", toRead.length, in.read(0, toRead, 0, toRead.length));
    } catch (IOException e) {
        return false;
    }
    return checkFile(toRead, expected);
}

18 View Complete Implementation : LogAggregationIndexedFileController.java
Copyright Apache License 2.0
Author : apache
private byte[] loadUUIDFromLogFile(final FileContext fc, final Path parent, final ApplicationId appId, final String nodeId) throws Exception {
    byte[] id = null;
    RemoteIterator<FileStatus> files = fc.listStatus(parent);
    FSDataInputStream fsDataInputStream = null;
    byte[] uuid = createUUID(appId);
    while (files.hasNext()) {
        try {
            Path checkPath = files.next().getPath();
            if (checkPath.getName().contains(LogAggregationUtils.getNodeString(nodeId)) && !checkPath.getName().endsWith(CHECK_SUM_FILE_SUFFIX)) {
                fsDataInputStream = fc.open(checkPath);
                byte[] b = new byte[uuid.length];
                int actual = fsDataInputStream.read(b);
                if (actual != uuid.length || Arrays.equals(b, uuid)) {
                    deleteFileWithRetries(fc, checkPath);
                } else if (id == null) {
                    id = uuid;
                }
            }
        } finally {
            IOUtils.cleanupWithLogger(LOG, fsDataInputStream);
        }
    }
    return id == null ? uuid : id;
}

18 View Complete Implementation : AuxServices.java
Copyright Apache License 2.0
Author : apache
/**
 * Reads the manifest file if it is configured, exists, and has not been
 * modified since the last read.
 *
 * @return aux service records
 * @throws IOException
 */
private synchronized AuxServiceRecords maybeReadManifestFile() throws IOException {
    if (manifest == null) {
        return null;
    }
    if (!manifestFS.exists(manifest)) {
        LOG.warn("Manifest file " + manifest + " doesn't exist");
        return null;
    }
    FileStatus status;
    try {
        status = manifestFS.getFileStatus(manifest);
    } catch (FileNotFoundException e) {
        LOG.warn("Manifest file " + manifest + " doesn't exist");
        return null;
    }
    if (!status.isFile()) {
        LOG.warn("Manifest file " + manifest + " is not a file");
    }
    if (!checkManifestOwnerAndPermissions(status)) {
        return null;
    }
    if (status.getModificationTime() == manifestModifyTS) {
        return null;
    }
    manifestModifyTS = status.getModificationTime();
    LOG.info("Reading auxiliary services manifest " + manifest);
    try (FSDataInputStream in = manifestFS.open(manifest)) {
        return mapper.readValue((InputStream) in, AuxServiceRecords.clreplaced);
    }
}

18 View Complete Implementation : ITestBlockBlobInputStream.java
Copyright Apache License 2.0
Author : apache
@Test
public void test_0200_BasicReadTest() throws Exception {
    replacedumeHugeFileExists();
    try (FSDataInputStream inputStreamV1 = accountUsingInputStreamV1.getFileSystem().open(TEST_FILE_PATH);
        FSDataInputStream inputStreamV2 = accountUsingInputStreamV2.getFileSystem().open(TEST_FILE_PATH)) {
        byte[] bufferV1 = new byte[3 * MEGABYTE];
        byte[] bufferV2 = new byte[bufferV1.length];
        // v1 forward seek and read a kilobyte into first kilobyte of bufferV1
        inputStreamV1.seek(5 * MEGABYTE);
        int numBytesReadV1 = inputStreamV1.read(bufferV1, 0, KILOBYTE);
        replacedertEquals(KILOBYTE, numBytesReadV1);
        // v2 forward seek and read a kilobyte into first kilobyte of bufferV2
        inputStreamV2.seek(5 * MEGABYTE);
        int numBytesReadV2 = inputStreamV2.read(bufferV2, 0, KILOBYTE);
        replacedertEquals(KILOBYTE, numBytesReadV2);
        replacedertArrayEquals(bufferV1, bufferV2);
        int len = MEGABYTE;
        int offset = bufferV1.length - len;
        // v1 reverse seek and read a megabyte into last megabyte of bufferV1
        inputStreamV1.seek(3 * MEGABYTE);
        numBytesReadV1 = inputStreamV1.read(bufferV1, offset, len);
        replacedertEquals(len, numBytesReadV1);
        // v2 reverse seek and read a megabyte into last megabyte of bufferV2
        inputStreamV2.seek(3 * MEGABYTE);
        numBytesReadV2 = inputStreamV2.read(bufferV2, offset, len);
        replacedertEquals(len, numBytesReadV2);
        replacedertArrayEquals(bufferV1, bufferV2);
    }
}