code: public static int read(InputStream input, byte[] buffer, int offset, int length) throws IOException {
          if (length < 0) {
              throw new IllegalArgumentException("Length must not be negative: " + length);
          }
          int remaining = length;
          try {
              while (remaining > 0) {
                  int location = length - remaining;
                  int count = input.read(buffer, offset + location, remaining);
                  if (EOF == count) { // EOF
                      break;
                  }
                  remaining -= count;
              }
          } finally {
              IOUtils.closeQuietly(input);
          }
          return length - remaining;
      }
docs: Read bytes from an input stream.
  This implementation guarantees that it will read as many bytes
  as possible before giving up; this may not always be the case for
  subclasses of {@link InputStream}.
  
  @param input  where to read input from
  @param buffer destination
  @param offset inital offset into buffer
  @param length length to read, must be >= 0
  @return actual length read; may be less than requested if EOF was reached
  @throws IOException if a read error occurs
  @since 2.2