@Override
  public void seek(long pos) throws IOException {
    if (pos < 0) {
      throw new EOFException(FSExceptionMessages.NEGATIVE_SEEK);
    }
    if (pos > this.fileSize) {
      throw new EOFException(FSExceptionMessages.CANNOT_SEEK_PAST_EOF);
    }

    if (this.position == pos) {
      return;
    }
    if (pos > position && pos < this.position + partRemaining) {
      long len = pos - this.position;
      this.position = pos;
      this.partRemaining -= len;
    } else {
      this.reopen(pos);
    }
  }
@Test
  public void testSeek() throws Exception {
    Path seekTestFilePath = new Path(this.testRootDir + "/"
        + "seekTestFile");
    long fileSize = 5 * Unit.MB;

    ContractTestUtils.generateTestFile(
        this.fs, seekTestFilePath, fileSize, 256, 255);
    LOG.info("5MB file for seek test has created.");

    FSDataInputStream inputStream = this.fs.open(seekTestFilePath);
    int seekTimes = 5;
    for (int i = 0; i != seekTimes; i++) {
      long pos = fileSize / (seekTimes - i) - 1;
      inputStream.seek(pos);
      assertTrue("expected position at: " +
              pos + ", but got: " + inputStream.getPos(),
          inputStream.getPos() == pos);
      LOG.info("completed seeking at pos: " + inputStream.getPos());
    }
    LOG.info("begin to random position seeking test...");
    Random random = new Random();
    for (int i = 0; i < seekTimes; i++) {
      long pos = Math.abs(random.nextLong()) % fileSize;
      LOG.info("seeking for pos: " + pos);
      inputStream.seek(pos);
      assertTrue("expected position at: " +
              pos + ", but got: " + inputStream.getPos(),
          inputStream.getPos() == pos);
      LOG.info("completed seeking at pos: " + inputStream.getPos());
    }
  }