private static boolean readWithExtraOnHeap(InputStream in, byte[] buf, int bufOffset,
    int necessaryLen, int extraLen) throws IOException {
    int heapBytesRead = 0;
    int bytesRemaining = necessaryLen + extraLen;
    try {
      while (bytesRemaining > 0) {
        int ret = in.read(buf, bufOffset, bytesRemaining);
        if (ret < 0) {
          if (bytesRemaining <= extraLen) {
            // We could not read the "extra data", but that is OK.
            break;
          }
          throw new IOException("Premature EOF from inputStream (read " + "returned " + ret
            + ", was trying to read " + necessaryLen + " necessary bytes and " + extraLen
            + " extra bytes, " + "successfully read " + (necessaryLen + extraLen - bytesRemaining));
        }
        bufOffset += ret;
        bytesRemaining -= ret;
        heapBytesRead += ret;
      }
    } finally {
      final Span span = Span.current();
      span.addEvent("BlockIOUtils.readWithExtra", getHeapBytesReadAttributes(span, heapBytesRead));
    }
    return bytesRemaining <= 0;
  }
Read from an input stream at least <code>necessaryLen</code> and if possible,
<code>extraLen</code> also if available. Analogous to
{@link IOUtils#readFully(InputStream, byte[], int, int)}, but specifies a number of "extra"
bytes to also optionally read.
@param in           the input stream to read from
@param buf          the buffer to read into
@param bufOffset    the destination offset in the buffer
@param necessaryLen the number of bytes that are absolutely necessary to read
@param extraLen     the number of extra bytes that would be nice to read
@return true if succeeded reading the extra bytes
@throws IOException if failed to read the necessary bytes
hbase-common/src/main/java/org/apache/hadoop/hbase/io/util/BlockIOUtils.java