### Question:
BlockInputStream extends InputStream implements Seekable { @Override public synchronized void seek(long pos) throws IOException { if (!initialized) { blockPosition = pos; return; } checkOpen(); if (pos < 0 || pos >= length) { if (pos == 0) { return; } throw new EOFException( "EOF encountered at pos: " + pos + " for block: " + blockID); } if (chunkIndex >= chunkStreams.size()) { chunkIndex = Arrays.binarySearch(chunkOffsets, pos); } else if (pos < chunkOffsets[chunkIndex]) { chunkIndex = Arrays.binarySearch(chunkOffsets, 0, chunkIndex, pos); } else if (pos >= chunkOffsets[chunkIndex] + chunkStreams .get(chunkIndex).getLength()) { chunkIndex = Arrays.binarySearch(chunkOffsets, chunkIndex + 1, chunkStreams.size(), pos); } if (chunkIndex < 0) { chunkIndex = -chunkIndex - 2; } chunkStreams.get(chunkIndexOfPrevPosition).resetPosition(); for (int index = chunkIndex + 1; index < chunkStreams.size(); index++) { chunkStreams.get(index).seek(0); } chunkStreams.get(chunkIndex).seek(pos - chunkOffsets[chunkIndex]); chunkIndexOfPrevPosition = chunkIndex; } BlockInputStream(BlockID blockId, long blockLen, Pipeline pipeline,
      Token<OzoneBlockTokenIdentifier> token, boolean verifyChecksum,
      XceiverClientFactory xceiverClientFctry,
      Function<BlockID, Pipeline> refreshPipelineFunction);  BlockInputStream(BlockID blockId, long blockLen, Pipeline pipeline,
                          Token<OzoneBlockTokenIdentifier> token,
                          boolean verifyChecksum,
                          XceiverClientManager xceiverClientFactory
  ); synchronized void initialize(); synchronized long getRemaining(); @Override synchronized int read(); @Override synchronized int read(byte[] b, int off, int len); @Override synchronized void seek(long pos); @Override synchronized long getPos(); @Override boolean seekToNewSource(long targetPos); @Override synchronized void close(); synchronized void resetPosition(); BlockID getBlockID(); long getLength();  }### Answer:
@Test public void testSeek() throws Exception { int pos = 0; seekAndVerify(pos); Assert.assertEquals("ChunkIndex is incorrect", 0, blockStream.getChunkIndex()); pos = CHUNK_SIZE; seekAndVerify(pos); Assert.assertEquals("ChunkIndex is incorrect", 0, blockStream.getChunkIndex()); Assert.assertEquals(pos, blockStream.getBlockPosition()); blockStream.initialize(); Assert.assertEquals("ChunkIndex is incorrect", 1, blockStream.getChunkIndex()); pos = (CHUNK_SIZE * 4) + 5; seekAndVerify(pos); Assert.assertEquals("ChunkIndex is incorrect", 4, blockStream.getChunkIndex()); try { pos = blockSize + 10; seekAndVerify(pos); Assert.fail("Seek to position beyond block size should fail."); } catch (EOFException e) { System.out.println(e); } Random random = new Random(); for (int i = 0; i < 10; i++) { pos = random.nextInt(blockSize); seekAndVerify(pos); } }