public String readPage(long page) throws IOException, InterruptedException {
    FSDataInputStream stream = UserLocalObjects.getHdfsApi(context).open(filePath);
    try {
      stream.seek(page * PAGE_SIZE);
    } catch (IOException e) {
      throw new IllegalArgumentException("Page " + page + " does not exists");
    }

    byte[] buffer = new byte[PAGE_SIZE];
    int readCount = 0;
    int read = 0;
    while(read < PAGE_SIZE) {
      try {
        readCount = stream.read(buffer, read, PAGE_SIZE-read);
      } catch (IOException e) {
        stream.close();
        throw e;
      }
      if (readCount == -1)
        break;
      read += readCount;
    }
    if (read != 0) {
      byte[] readData = Arrays.copyOfRange(buffer, 0, read);
      return new String(readData, Charset.forName("UTF-8"));
    } else {
      if (page == 0) {
        return "";
      }
      throw new IllegalArgumentException("Page " + page + " does not exists");
    }
  }
Read one page of size PAGE_SIZE
@param page page index
@return data in UTF-8
@throws IOException
@throws InterruptedException
contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/FilePaginator.java