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:net.sourceforge.doddle_owl.utils.Utils.java
public static File getJPWNFile(String resName) { File dir = new File(JPWN_TEMP_DIR); if (!dir.exists()) { dir.mkdir();// www. j ava 2 s. com } File file = new File(JPWN_TEMP_DIR + resName); if (file.exists()) { // System.out.println("exist: " + file.getAbsolutePath()); return file; } URL url = DODDLE_OWL.class.getClassLoader().getResource(RESOURCE_DIR + DODDLEConstants.JPWN_HOME + resName); try { FileUtils.copyURLToFile(url, file); } catch (IOException e) { e.printStackTrace(); } // System.out.println("created: " + file.getAbsolutePath()); return file; }
From source file:eu.excitementproject.eop.distsim.redisinjar.EmbeddedRedisServerRunner.java
private File extractExecutableFromJar(String scriptName) throws IOException { File tmpDir = Files.createTempDir(); tmpDir.deleteOnExit();// ww w . j a v a2 s. c om File command = new File(tmpDir, scriptName); FileUtils.copyURLToFile(Resources.getResource(scriptName), command); command.deleteOnExit(); command.setExecutable(true); return command; }
From source file:com.diffplug.gradle.p2.P2BootstrapInstallation.java
/** Installs the bootstrap installation. */ private void install() throws IOException { System.out.print("Installing p2 bootstrap " + release + "... "); // clean the install folder FileMisc.cleanDir(getRootFolder());//from w ww. j av a2 s .c o m // download the URL File target = new File(getRootFolder(), DOWNLOAD_FILE); URL url = new URL(DOWNLOAD_ROOT + release.version() + DOWNLOAD_FILE); FileUtils.copyURLToFile(url, target); // unzip it ZipMisc.unzip(target, target.getParentFile()); // delete the zip FileMisc.forceDelete(target); FileMisc.writeToken(getRootFolder(), TOKEN); System.out.print("Success."); }
From source file:com.bladecoder.engineeditor.model.Chapter.java
public String createChapter(String id) throws TransformerException, ParserConfigurationException, IOException { String checkedId = ElementUtils.getCheckedId(id, getChapters()); URL inputUrl = getClass().getResource("/projectTmpl/android/assets/model/00.chapter.json"); File dest = new File(modelPath + checkedId + EngineAssetManager.CHAPTER_EXT); FileUtils.copyURLToFile(inputUrl, dest); return checkedId; }
From source file:io.jenkins.plugins.pipelineaction.sources.GlobalRepoPipelineActionTest.java
@Test public void invalidStepsInAction() { story.addStep(new Statement() { @Override/* w ww . java 2 s . c om*/ public void evaluate() throws Throwable { File dir = new File(repo.workspace, "actions/io/jenkins/plugins/pipelineaction/sources"); dir.mkdirs(); File outFile = new File(dir, "InvalidStepsAction.groovy"); FileUtils.copyURLToFile(getClass().getResource( "/io/jenkins/plugins/pipelineaction/sources/InvalidStepsAction.groovy"), outFile); // Hack to deal with the lack of an actual commit. globalRepoPipelineActionSet.rebuild(); WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("runPipelineAction(['name':'InvalidStepsAction',\n" + "pants:'trousers',\n" + "shirts:'polos'])\n")); // get the build going WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get(); story.j.assertBuildStatus(Result.FAILURE, story.j.waitForCompletion(b)); story.j.assertLogContains("Blacklisted steps used in action", b); story.j.assertLogContains("Expression [MethodCallExpression] is not allowed: script.node", b); } }); }
From source file:api.wiki.WikiNameApi2.java
private TreeMap<String, String> getGenderNameContinue(String title, String continueString) { String query = BASE_URL + "&list=categorymembers&cmlimit=500&cmtitle=" + title.replaceAll("\\s+", "_") + "&cmprop=title&cmcontinue=" + continueString; TreeMap<String, String> values = new TreeMap<>(); try {/*from ww w. j a va 2 s. c om*/ URL url = new URL(query); File file = File.createTempFile("WIKI_", title); FileUtils.copyURLToFile(url, file); String s = FileUtils.readFileToString(file); JSONObject j = new JSONObject(s); if (j.has("query-continue")) { values.putAll(getGenderNameContinue(title, j.getJSONObject("query-continue") .getJSONObject("categorymembers").getString("cmcontinue"))); } JSONArray json = j.getJSONObject("query").getJSONArray("categorymembers"); for (int i = 0; i < json.length(); i++) { String value = json.getJSONObject(i).getString("title"); String key = value; if (key.contains("(")) { key = key.substring(0, key.indexOf("(")); } values.put(key, value); } } catch (IOException ex) { Logger.getLogger(WikiNameApi2.class.getName()).log(Level.SEVERE, null, ex); } return values; }
From source file:com.clothcat.rfcreader.network.RfcFetcher.java
/** * Fetch the RFC referred to by number./* ww w . j a va2 s . c om*/ * * @param num The RFC to fetch * @param overwrite Whether to overwrite any existing file. * @throws java.nio.file.FileAlreadyExistsException */ public static void fetchRfc(int num, boolean overwrite) throws FileAlreadyExistsException { makeDirs(); String base_location = Constants.RFC_BASE_LOCATION; String s = "rfc" + num + ".txt"; File filename = new File(Constants.RFC_CACHE + s); if (filename.exists()) { if (!overwrite) { throw new FileAlreadyExistsException(filename.getAbsolutePath()); } else { filename.delete(); } } try { URL u = new URL(base_location + s); FileUtils.copyURLToFile(u, filename); } catch (MalformedURLException ex) { Logger.getLogger(RfcFetcher.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RfcFetcher.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.liferay.ide.project.core.modules.BladeCLI.java
public static synchronized File fetchBladeJarFromRepo(boolean useCache) throws Exception { if (!useCache) { _bladeJarCacheFile = null;/*from w ww. j av a2s. c o m*/ } if (_bladeJarCacheFile == null) { File bladeFile = new File(_repoCache.getAbsolutePath(), BLADE_JAR_FILE_NAME); String urlStr = _getRepoURL() + "/" + BLADE_JAR_FILE_NAME; URL url = new URL(urlStr); FileUtils.copyURLToFile(url, bladeFile); _bladeJarCacheFile = bladeFile; return bladeFile; } else { return _bladeJarCacheFile; } }
From source file:com.liferay.blade.cli.SamplesCommand.java
private boolean downloadBladeRepoIfNeeded() throws Exception { File bladeRepoArchive = new File(_blade.getCacheDir(), _BLADE_REPO_ARCHIVE_NAME); Date now = new Date(); long diff = now.getTime() - bladeRepoArchive.lastModified(); if (!bladeRepoArchive.exists() || (diff > _FILE_EXPIRATION_TIME)) { FileUtils.copyURLToFile(new URL(_BLADE_REPO_URL), bladeRepoArchive); return true; }/*from w w w . j a v a 2s . co m*/ return false; }
From source file:com.linkedin.pinot.tools.HybridQuickstart.java
private QuickstartTableRequest prepareRealtimeTableRequest() throws IOException { _realtimeQuickStartDataDir = new File("quickStartData" + System.currentTimeMillis()); String quickStartDataDirName = _realtimeQuickStartDataDir.getName(); if (!_realtimeQuickStartDataDir.exists()) { _realtimeQuickStartDataDir.mkdir(); }// w ww . j a va2 s .c o m File schema = new File(quickStartDataDirName + "/airlineStats.schema"); File tableCreate = new File(quickStartDataDirName + "/airlineStatsRealtime_hybrid.json"); FileUtils.copyURLToFile( RealtimeQuickStart.class.getClassLoader().getResource("sample_data/airlineStats.schema"), schema); FileUtils.copyURLToFile(RealtimeQuickStart.class.getClassLoader() .getResource("sample_data/airlineStatsRealtime_hybrid.json"), tableCreate); return new QuickstartTableRequest("airlineStats", schema, tableCreate); }