public static void copyFromStreamToBuffer(ByteBuffer out, DataInputStream in, int length)
            throws IOException {
        if (out.hasArray()) {
            in.readFully(out.array(), out.position() + out.arrayOffset(), length);
            skip(out, length);
        } else {
            for (int i = 0; i < length; ++i) {
                out.put(in.readByte());
            }
        }
    }
Copy the given number of bytes from the given stream and put it at the current position of the
given buffer, updating the position in the buffer.

@param out    the buffer to write data to
@param in     the stream to read data from
@param length the number of bytes to read/write
stroom-bytebuffer/src/main/java/stroom/bytebuffer/hbase/ByteBufferUtils.java