List of usage examples for org.apache.commons.io FileUtils copyURLToFile
public static void copyURLToFile(URL source, File destination) throws IOException
source
to a file destination
. From source file:io.vertx.config.vault.utils.VaultDownloader.java
public static File download() { File out = new File("target/vault/vault"); if (SystemUtils.IS_OS_WINDOWS) { out = new File("target/vault/vault.exe"); }/* w ww. ja v a2s. com*/ if (out.isFile()) { return out; } File zip = new File("target/vault.zip"); try { FileUtils.copyURLToFile(getURL(VaultProcess.VAULT_VERSION), zip); } catch (Exception e) { throw new RuntimeException(e); } assert zip.isFile(); System.out.println(zip.getAbsolutePath() + " has been downloaded, unzipping"); try { unzip(zip, out.getParentFile()); } catch (IOException e) { throw new RuntimeException(e); } System.out.println("Vault: " + out.getAbsolutePath()); assert out.isFile(); out.setExecutable(true); assert out.canExecute(); return out; }
From source file:net.fabricmc.installer.installer.ServerInstaller.java
public static void install(File mcDir, String version, IInstallerProgress progress) throws IOException { File fabricJar = new File(mcDir, Reference.NAME_FABRIC_LOADER + "-" + version + ".jar"); if (fabricJar.exists()) { fabricJar.delete();/*from ww w . j a v a 2 s . co m*/ } progress.updateProgress(Translator.getString("install.server.downloadFabric"), 5); FileUtils.copyURLToFile(new URL(MavenHandler.getPath(Reference.MAVEN_SERVER_URL, Reference.PACKAGE_FABRIC, Reference.NAME_FABRIC_LOADER, version)), fabricJar); install(mcDir, version, progress, fabricJar); }
From source file:eu.riscoss.RemoteRiskAnalyserMain.java
static void loadJSmile() throws Exception { File dir = new File(FileUtils.getTempDirectory(), "jnativelibs-" + RandomStringUtils.randomAlphabetic(30)); if (!dir.mkdir()) { throw new Exception("failed to make dir"); }//from www . j a v a 2 s.c o m File jsmile = new File(dir, "libjsmile.so"); URL jsmURL = Thread.currentThread().getContextClassLoader().getResource("libjsmile.so"); FileUtils.copyURLToFile(jsmURL, jsmile); System.setProperty("java.library.path", System.getProperty("java.library.path") + ":" + dir.getAbsolutePath()); // flush the library paths Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths"); sysPathsField.setAccessible(true); sysPathsField.set(null, null); // Check that it works... System.loadLibrary("jsmile"); dir.deleteOnExit(); jsmile.deleteOnExit(); }
From source file:com.hazelcast.example.mapreduce.downloader.ImageDownloaderMapper.java
public static Long saveImage(String sourceUrl, String destUrl) { File file = new File(destUrl); URL url;/*from w w w. j a v a 2 s .c om*/ try { //url = new URL(URLEncoder.encode(sourceUrl, "UTF-8")); url = new URL(sourceUrl); FileUtils.copyURLToFile(url, file); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return file.length(); }
From source file:com.linkedin.pinot.common.TestUtils.java
public static String getFileFromResourceUrl(URL resourceUrl) { System.out.println(resourceUrl); // Check if we need to extract the resource to a temporary directory String resourceUrlStr = resourceUrl.toString(); if (resourceUrlStr.contains("jar!")) { try {/*from ww w . ja v a 2 s.co m*/ String extension = resourceUrlStr.substring(resourceUrlStr.lastIndexOf('.')); File tempFile = File.createTempFile("pinot-test-temp", extension); LOGGER.info("Extractng from " + resourceUrlStr + " to " + tempFile.getAbsolutePath()); System.out.println("Extractng from " + resourceUrlStr + " to " + tempFile.getAbsolutePath()); FileUtils.copyURLToFile(resourceUrl, tempFile); return tempFile.getAbsolutePath(); } catch (IOException e) { throw new RuntimeException(e); } } else { System.out.println("Not extracting plain file " + resourceUrl); return resourceUrl.getFile(); } }
From source file:net.fabricmc.installer.installer.ClientInstaller.java
public static void install(File mcDir, String version, IInstallerProgress progress) throws IOException { String[] split = version.split("-"); if (isValidInstallLocation(mcDir, split[0]).isPresent()) { throw new RuntimeException(isValidInstallLocation(mcDir, split[0]).get()); }/*from ww w.j a va2 s . c o m*/ File fabricData = new File(mcDir, "fabricData"); File fabricJar = new File(fabricData, version + ".jar"); if (!fabricJar.exists()) { progress.updateProgress(Translator.getString("install.client.downloadFabric"), 10); FileUtils.copyURLToFile(new URL(MavenHandler.getPath(Reference.MAVEN_SERVER_URL, Reference.PACKAGE_FABRIC, Reference.NAME_FABRIC_LOADER, version)), fabricJar); } JarFile jarFile = new JarFile(fabricJar); Attributes attributes = jarFile.getManifest().getMainAttributes(); String mcVersion = attributes.getValue("MinecraftVersion"); install(mcDir, mcVersion, progress, fabricJar); FileUtils.deleteDirectory(fabricData); }
From source file:costumetrade.common.util.PdfUtils.java
public static PDDocument createImagePdf(String urlString) { File file = null;/*from ww w . j a v a 2 s.co m*/ try { URL url = new URL(urlString); file = new File(path + url.getFile()); FileUtils.copyURLToFile(url, file); return createImagePdf(file); } catch (IOException e) { throw new RuntimeException("?PDF", e); } finally { if (file != null) { file.delete(); } } }
From source file:minecrunch_updater.Minecrunch_updater.java
private static void VersionCheck() throws MalformedURLException { // Get system properties String os = System.getProperty("os.name"); String home = System.getProperty("user.home"); String dir;/* w ww.j av a 2 s . co m*/ String newfile2 = null; if (os.contains("Windows")) { dir = home + "\\.minecrunch\\"; newfile2 = dir + "\\resources\\"; } else { dir = home + "/.minecrunch/"; newfile2 = dir + "/resources/"; } try { // Get version.txt from server URL url = new URL("http://www.minecrunch.net/download/minecrunch_installer/version.txt"); File file = new File(dir + "version.txt"); File file2 = new File(newfile2 + "version.txt"); FileUtils.copyURLToFile(url, file); boolean isTwoEqual = FileUtils.contentEquals(file, file2); if (isTwoEqual) { System.out.println("Up to date."); Run(); } else { Object[] options = { "Yes, please", "No way!" }; Component frame = null; // Get answer if the user wants to update or not int n = JOptionPane.showOptionDialog(frame, "There is an update to Minecrunch Modpack.", "Would you like to update now?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { // If yes run the Update method Update(); } else { // If user chooses no then just run the minecrunch_launcher jar file Run(); } } } catch (IOException ex) { Logger.getLogger(Minecrunch_updater.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:kyotocabinet.Loader.java
/** * Load the native library.//from w w w . java 2s .c o m */ static synchronized void load() { if (loaded) { return; } String lib = System.mapLibraryName("jkyotocabinet"); if (lib.endsWith(".dll")) { // lib?lib URL url = Loader.class.getClassLoader().getResource(System.mapLibraryName("jkyotocabinet")); String libFileName = "./temp" + File.separatorChar + System.mapLibraryName("jkyotocabinet"); File file = new File(libFileName); try { FileUtils.copyURLToFile(url, file); } catch (IOException e) { throw new RuntimeException(e); } System.load(file.getAbsolutePath()); } else { System.loadLibrary("jkyotocabinet"); } loaded = true; }
From source file:com.opoopress.maven.plugins.plugin.downloader.SimpleURLDownloader.java
@Override public void download(URL address, File destination) throws IOException { FileUtils.copyURLToFile(address, destination); }