public static ByteBuffer drainInputStreamToBuffer(InputStream is) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
        IOUtils.copyBytes(is, baos, 4096, true);
        ByteBuffer buffer = ByteBuffer.wrap(baos.toByteArray());
        buffer.rewind();
        return buffer;
    }
Copy from the InputStream to a new heap ByteBuffer until the InputStream is exhausted.
stroom-bytebuffer/src/main/java/stroom/bytebuffer/hbase/ByteBufferUtils.java