public static void readFully(FSDataInputStream reader, long offset, ByteBuffer buffer) throws IOException {
        if (offset >= 0) {
            reader.seek(offset);
        }

        InputStream is = reader.getWrappedStream();

        if (!(is instanceof ByteBufferReadable)) {
            logger.trace("Using read bytes method");
            byte[] bytes = new byte[buffer.remaining()];
            reader.readFully(bytes);
            buffer.put(bytes);
        } else {
            while (buffer.hasRemaining()) {
                int pos = buffer.position();
                int rt = reader.read(buffer);
                if (rt < 0) {
                    throw new IOException("End of stream");
                }
                buffer.position(pos + rt);
            }
        }
        Preconditions.checkState(!buffer.hasRemaining());
    }
Slow function, should only used in test. Unless, you choose to optimize it.
This function will not move the position of <i>from</i>.
indexr-common/src/main/java/io/indexr/util/IOUtil.java