public static long readLong(InputStream in) throws IOException {
    long result = 0;
    for (int shift = 56; shift >= 0; shift -= 8) {
      long x = in.read();
      if (x < 0) throw new IOException("EOF");
      result |= (x << shift);
    }
    return result;
  }
Read a byte from the given stream using the read method, and throw EOFException if it returns
-1, like the implementation in {@code DataInputStream}.
<p/>
This is useful because casting the return value of read method into byte directly will make us
lose the ability to check whether there is a byte and its value is -1 or we reach EOF, as
casting int -1 to byte also returns -1.
hbase-common/src/main/java/org/apache/hadoop/hbase/io/util/StreamUtils.java