private static ByteBuffer readFileIntoBuffer(RandomAccessFile file, boolean useDirect) throws IOException {
    if (file.length() > Integer.MAX_VALUE) {
      throw new IllegalStateException("Configured to keep indexes in memory but index file length > IntegerMax");
    }
    ByteBuffer buf =
        useDirect ? ByteBuffer.allocateDirect((int) file.length()) : ByteBuffer.allocate((int) file.length());
    file.getChannel().read(buf);
    return buf;
  }
Read a full {@link RandomAccessFile} into a buffer.
@param file the file to read.
@param useDirect {@code true} to allocate a direct buffer instead of a heap buffer.
@return the buffer containing the contents of {@code file}
@throws IOException on read failure.
ambry-store/src/main/java/com/github/ambry/store/IndexSegment.java