public static void copyStreamToFile(InputStream from, File to) throws IOException {
    File directory = to.getParentFile();
    if (!(directory.isDirectory() || directory.mkdirs())) {
      throw new IOException("Cannot create: " + directory);
    }
    try (OutputStream out = new BufferedOutputStream(new FileOutputStream(to))) {
      copyStream(from, out);
    }
  }
public static void copyStreamToFile(InputStream from, File to)