public static int eagerRead(final InputStream stream, final byte[] buffer) throws IOException {
        int read = 0;
        int offset = 0;
        int remaining = buffer.length;
        while (remaining > 0 && (read = stream.read(buffer, offset, remaining)) != -1) {
            remaining = remaining - read;
            offset = offset + read;
        }

        // Did not read anything ... must be finished
        if (offset == 0) {
            return -1;
        }

        // Length read
        return offset;
    }
Try a read a full buffer from a stream.

@param stream to read from
@param buffer to read into
@throws IOException if error
stroom-legacy/stroom-legacy-model_6_1/src/main/java/stroom/legacy/model_6_1/StreamUtil.java