class StreamUtils {

    public static int read(InputStream input, byte[] buffer) throws IOException {
        if(input == null || buffer == null) {
            return -1;
        }

        int remaining = buffer.length;
        while (remaining > 0) {
            int location = buffer.length - remaining;
            int count = input.read(buffer, 0 + location, remaining);
            if (EOF == count) { // EOF
                break;
            }
            remaining -= count;
        }
        return buffer.length - remaining;
    }

    private  StreamUtils();

}