code: public static byte[] bytes(InputStream in) throws IOException {
          if (in == null) {
              throw new IllegalArgumentException("input stream cannot be null");
          }
          ByteArrayOutputStream os = null;
          try {
              os = new ByteArrayOutputStream(1024);
              byte[] bytes = new byte[1024];
              int len;
              while ((len = in.read(bytes)) != -1) {
                  os.write(bytes, 0, len);
              }
              return os.toByteArray();
          } finally {
              closeQuietly(os);
          }
      }
docs: Reads contents of the input stream fully and returns it as byte array.
  
  @param in InputStream to read from.
  @return contents of the input stream fully as byte array
  @throws IOException in case of IO error