@Override
    public void readFully(long position, byte[] buffer, int offset, int length)
            throws IOException
    {
        int totalBytesRead = 0;
        while (totalBytesRead < length) {
            int bytesRead = read(
                    position + totalBytesRead,
                    buffer,
                    offset + totalBytesRead,
                    length - totalBytesRead);
            if (bytesRead == -1) {
                throw new EOFException();
            }
            totalBytesRead += bytesRead;
        }
    }
@Test
    public void testValidateDataEnabledWithDataMismatch()
            throws IOException
    {
        byte[] inputData = new byte[] {1, 2, 3};
        byte[] corruptedData = new byte[] {1, 3, 3};
        FSDataInputStream dataTierInputStream = new TestFSDataInputStream(inputData);
        FSDataInputStream fileInStream = new TestFSDataInputStream(corruptedData);
        CacheValidatingInputStream fileInputStream =
                new CacheValidatingInputStream(fileInStream, dataTierInputStream);
        byte[] buffer = new byte[3];
        try {
            fileInputStream.readFully(0, buffer, 0, buffer.length);
            fail("Data validation didn't work for mismatched data.");
        }
        catch (VerifyException ex) {
            assertEquals(ex.getMessage(), "corrupted buffer at position 1");
        }
    }