### Question:
HFileBlock extends SchemaConfigured implements Cacheable { void sanityCheck() throws IOException { buf.rewind(); { BlockType blockTypeFromBuf = BlockType.read(buf); if (blockTypeFromBuf != blockType) { throw new IOException("Block type stored in the buffer: " + blockTypeFromBuf + ", block type field: " + blockType); } } sanityCheckAssertion(buf.getInt(), onDiskSizeWithoutHeader, "onDiskSizeWithoutHeader"); sanityCheckAssertion(buf.getInt(), uncompressedSizeWithoutHeader, "uncompressedSizeWithoutHeader"); sanityCheckAssertion(buf.getLong(), prevBlockOffset, "prevBlocKOffset"); if (minorVersion >= MINOR_VERSION_WITH_CHECKSUM) { sanityCheckAssertion(buf.get(), checksumType, "checksumType"); sanityCheckAssertion(buf.getInt(), bytesPerChecksum, "bytesPerChecksum"); sanityCheckAssertion(buf.getInt(), onDiskDataSizeWithHeader, "onDiskDataSizeWithHeader"); } int cksumBytes = totalChecksumBytes(); int hdrSize = headerSize(); int expectedBufLimit = uncompressedSizeWithoutHeader + headerSize() + cksumBytes; if (buf.limit() != expectedBufLimit) { throw new AssertionError("Expected buffer limit " + expectedBufLimit + ", got " + buf.limit()); } int size = uncompressedSizeWithoutHeader + hdrSize + cksumBytes; if (buf.capacity() != size && buf.capacity() != size + hdrSize) { throw new AssertionError("Invalid buffer capacity: " + buf.capacity() + ", expected " + size + " or " + (size + hdrSize)); } } HFileBlock(BlockType blockType, int onDiskSizeWithoutHeader,
      int uncompressedSizeWithoutHeader, long prevBlockOffset, ByteBuffer buf,
      boolean fillHeader, long offset, boolean includesMemstoreTS, 
      int minorVersion, int bytesPerChecksum, byte checksumType,
      int onDiskDataSizeWithHeader);   HFileBlock(ByteBuffer b, int minorVersion); BlockType getBlockType(); short getDataBlockEncodingId(); int getOnDiskSizeWithHeader(); int getUncompressedSizeWithoutHeader(); long getPrevBlockOffset(); ByteBuffer getBufferReadOnly(); @Override String toString(); void assumeUncompressed(); void expectType(BlockType expectedType); long getOffset(); DataInputStream getByteStream(); @Override long heapSize(); static boolean readWithExtra(InputStream in, byte buf[],
      int bufOffset, int necessaryLen, int extraLen); int getNextBlockOnDiskSizeWithHeader(); @Override int getSerializedLength(); @Override void serialize(ByteBuffer destination); @Override CacheableDeserializer<Cacheable> getDeserializer(); @Override boolean equals(Object comparison); boolean doesIncludeMemstoreTS(); DataBlockEncoding getDataBlockEncoding(); int headerSize(); byte[] getDummyHeaderForVersion(); static final boolean FILL_HEADER; static final boolean DONT_FILL_HEADER; static final int ENCODED_HEADER_SIZE; static final int BYTE_BUFFER_HEAP_SIZE; }### Answer:
@Test public void testReaderV1() throws IOException { for (Compression.Algorithm algo : COMPRESSION_ALGORITHMS) { for (boolean pread : new boolean[] { false, true }) { byte[] block = createTestV1Block(algo); Path path = new Path(TEST_UTIL.getDataTestDir(), "blocks_v1_"+ algo); LOG.info("Creating temporary file at " + path); FSDataOutputStream os = fs.create(path); int totalSize = 0; int numBlocks = 50; for (int i = 0; i < numBlocks; ++i) { os.write(block); totalSize += block.length; } os.close(); FSDataInputStream is = fs.open(path); HFileBlock.FSReader hbr = new HFileBlock.FSReaderV1(is, algo, totalSize); HFileBlock b; int numBlocksRead = 0; long pos = 0; while (pos < totalSize) { b = hbr.readBlockData(pos, block.length, uncompressedSizeV1, pread); b.sanityCheck(); pos += block.length; numBlocksRead++; } assertEquals(numBlocks, numBlocksRead); is.close(); } } }