code: public static void saveTo(String path, InputStream in) {
          if (in == null) {
              throw new IllegalArgumentException("input stream cannot be null");
          }
          if (path == null) {
              throw new IllegalArgumentException("path cannot be null");
          }
  
          FileOutputStream out = null;
          try {
              out = new FileOutputStream(path);
              byte[] bytes = new byte[1024];
              int len;
              while ((len = in.read(bytes)) != -1) {
                  out.write(bytes, 0, len);
              }
              out.flush();
          } catch (IOException e) {
              throw new RuntimeException(e);
          } finally {
              closeQuietly(out);
          }
      }
docs: Saves content read from input stream into a file.
  
  @param path path to file.
  @param in  input stream to read content from.