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.github.blindio.prospero.core.browserdrivers.phantomjs.PhantomJSInstaller.java
static void installPhantomJS() { File tempArchive = null;//from w w w . j av a 2 s .c om try { tempArchive = File.createTempFile(PHANTOMJS_FILE_PREFIX, ArchiveFormat.getFileExtention()); FileUtils.copyURLToFile(new URL(PhantomJSArchiveFile.getDownloadURL()), tempArchive); tempArchive.deleteOnExit(); UnArchiver unarchiver = ArchiveFormat.getUnArchiver(); unarchiver.setSourceFile(tempArchive); File destDir = new File(getPhantomJSInstallDirPath()); if (!destDir.exists()) { destDir.mkdir(); } unarchiver.setDestDirectory(destDir); unarchiver.extract(); } catch (Exception e) { throw new ProsperoRuntimeAutomationException(e); } }
From source file:hudson.PluginManagerUtil.java
public static void dynamicLoad(String plugin, Jenkins jenkins) throws IOException, InterruptedException, RestartRequiredException { URL src = PluginManagerTest.class.getClassLoader().getResource("plugins/" + plugin); File dest = new File(jenkins.getRootDir(), "plugins/" + plugin); FileUtils.copyURLToFile(src, dest); jenkins.pluginManager.dynamicLoad(dest); }
From source file:hoot.services.controllers.info.ErrorLogTest.java
@BeforeClass public static void beforeClass() throws Exception { URL inputUrl = ErrorLogTest.class.getResource("/hoot/services/info/catalina.out"); File dest = new File(testFolder, "catalina.out"); FileUtils.copyURLToFile(inputUrl, dest); original_ERROR_LOG_PATH = ERROR_LOG_PATH; original_TEMP_OUTPUT_PATH = TEMP_OUTPUT_PATH; HootCustomPropertiesSetter.setProperty("ERROR_LOG_PATH", dest.getAbsolutePath()); HootCustomPropertiesSetter.setProperty("TEMP_OUTPUT_PATH", FileUtils.getTempDirectory().getAbsolutePath()); }
From source file:com.cloudera.knittingboar.utils.DataUtils.java
public static synchronized File getTwentyNewsGroupDir() throws IOException { if (twentyNewsGroups != null) { return twentyNewsGroups; }// w w w .j a v a 2s. c o m // mac gives unique tmp each run and we want to store this persist // this data across restarts File tmpDir = new File("/tmp"); if (!tmpDir.isDirectory()) { tmpDir = new File(System.getProperty("java.io.tmpdir")); } File baseDir = new File(tmpDir, TWENTY_NEWS_GROUP_LOCAL_DIR); if (!(baseDir.isDirectory() || baseDir.mkdir())) { throw new IOException("Could not mkdir " + baseDir); } File tarFile = new File(baseDir, TWENTY_NEWS_GROUP_TAR_FILE_NAME); if (!tarFile.isFile()) { FileUtils.copyURLToFile(new URL(TWENTY_NEWS_GROUP_TAR_URL), tarFile); } Process p = Runtime.getRuntime() .exec(String.format("tar -C %s -xvf %s", baseDir.getAbsolutePath(), tarFile.getAbsolutePath())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); System.out.println("Here is the standard error of the command (if any):\n"); String s; while ((s = stdError.readLine()) != null) { System.out.println(s); } stdError.close(); twentyNewsGroups = baseDir; return twentyNewsGroups; }
From source file:io.fabric8.maven.rt.ReadYaml.java
public BoosterYaml readYaml(String boosterUrl) throws IOException { //Lets convert the string boosterUrl to URl format. URL url = new URL(boosterUrl); //Create a temp file to read the data from URL File file = File.createTempFile("booster", ".yaml"); //Read the data from URl and copy it to File FileUtils.copyURLToFile(url, file); //Lets convert the file Bosster Yaml object and return BoosterYaml Object final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); return mapper.readValue(file, BoosterYaml.class); }
From source file:com.linkedin.pinot.util.TestUtils.java
public static String getFileFromResourceUrl(@Nonnull URL resourceUrl) { // For maven cross package use case, we need to extract the resource from jar to a temporary directory. String resourceUrlStr = resourceUrl.toString(); if (resourceUrlStr.contains("jar!")) { try {/*from w ww . java2 s .c om*/ String extension = resourceUrlStr.substring(resourceUrlStr.lastIndexOf('.')); File tempFile = File.createTempFile("pinot-test-temp", extension); String tempFilePath = tempFile.getAbsolutePath(); LOGGER.info("Extracting from " + resourceUrlStr + " to " + tempFilePath); FileUtils.copyURLToFile(resourceUrl, tempFile); return tempFilePath; } catch (IOException e) { throw new RuntimeException(e); } } else { return resourceUrl.getFile(); } }
From source file:hoot.services.controllers.job.JobFieldsValidatorTest.java
@BeforeClass public static void beforeClass() throws Exception { URL inputUrl = JobFieldsValidatorTest.class .getResource("/hoot.services.controllers.job/services_fields_metadata.json"); File dest = new File(new File(testFolder, "scripts/services"), "services_fields_metadata.json"); FileUtils.copyURLToFile(inputUrl, dest); originalHomeFolderDir = HOME_FOLDER; HootCustomPropertiesSetter.setProperty("HOME_FOLDER", testFolder.getAbsolutePath()); }
From source file:com.jomp16.swfripper.DownloadManager.java
@Override public void run() { File file = new File(path); if (!file.exists()) { try {//from w w w.j a v a 2 s . com Main.getLogging().writeLine("DownloadingFile", url); FileUtils.copyURLToFile(new URL(url), file); Main.getLogging().writeLine("DownloadedFile", url); } catch (IOException e) { System.err.println(e.getLocalizedMessage()); } } else { try { Main.getLogging().writeLine("BypassingFile", url); } catch (IOException e) { System.err.println(e.getLocalizedMessage()); } } }
From source file:hoot.services.validators.job.JobFieldsValidatorTest.java
@BeforeClass public static void beforeClass() throws Exception { URL inputUrl = JobFieldsValidatorTest.class .getResource("/hoot/services/validators/job/services_fields_metadata.json"); File dest = new File(new File(testFolder, "scripts"), "services_fields_metadata.json"); FileUtils.copyURLToFile(inputUrl, dest); originalHomeFolderDir = HOME_FOLDER; HootCustomPropertiesSetter.setProperty("HOME_FOLDER", testFolder.getAbsolutePath()); }
From source file:net.infstudio.inflauncher.game.downloading.MinecraftDownloader.java
@Override public boolean download() { String url = InfinityDownloader.mirrorManager.getFastestS3MirrorURL(); String metaUrl = InfinityDownloader.mirrorManager.getFastestMetaMirrorURL(); String librariesUrl = InfinityDownloader.mirrorManager.getFastestMavenMirrorURL(); try {/* ww w . j a v a 2s. co m*/ FileUtils.copyURLToFile(new URL(url + "/Minecraft.Download/versions/" + minecraft.getJar() + ".json"), new File(minecraft.getJar() + ".json")); } catch (IOException e) { InfinityDownloader.logger.error(e.getLocalizedMessage(), e); } return false; }