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:com.microsoft.azuretools.hdinsight.util.HDInsightJobViewUtils.java
private static void extractJobViewResource() { URL url = HDInsightJobViewUtils.class.getResource("/resources/" + HTML_ZIP_FILE_NAME); URL hdinsightJobViewJarUrl = HDInsightJobViewUtils.class .getResource("/resources/" + HDINSIGHT_JOB_VIEW_JAR_NAME); if (url == null || hdinsightJobViewJarUrl == null) { DefaultLoader.getUIHelper().showError("Cann't find Spark job view resources", "Job view"); return;//w w w . j ava2s.c o m } File indexRootFile = new File(PluginUtil.pluginFolder, HDINSIGIHT_FOLDER_NAME); if (indexRootFile.exists()) { FileUtils.deleteQuietly(indexRootFile); } File htmlRootFile = new File(indexRootFile.getPath(), "html"); htmlRootFile.mkdirs(); File htmlToFile = new File(htmlRootFile.getAbsolutePath(), HTML_ZIP_FILE_NAME); File hdinsightJobViewToFile = new File(indexRootFile, HDINSIGHT_JOB_VIEW_JAR_NAME); try { FileUtils.copyURLToFile(url, htmlToFile); FileUtils.copyURLToFile(hdinsightJobViewJarUrl, hdinsightJobViewToFile); HDInsightJobViewUtils.unzip(htmlToFile.getAbsolutePath(), htmlToFile.getParent()); DefaultLoader.getIdeHelper().setProperty(HDINSIGHT_JOBVIEW_EXTRACT_FLAG, "true"); } catch (IOException e) { DefaultLoader.getUIHelper().showError("Extract Job View Folder error:" + e.getMessage(), "Job view"); } }
From source file:de.arago.rike.leaderboard.LeaderBoardImagesServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("image/png"); try {/* w w w . ja v a2 s.co m*/ SVGDataServlet.addExpires(response); int pos = request.getRequestURL().lastIndexOf("/"); String name = request.getRequestURL().substring(pos + 1); File tmp = new File(System.getProperty("java.io.tmpdir"), name); if (!tmp.exists()) { String uri = GlobalConfig.get(GlobalConfig.PATH_TO_PERSONAL_PICS); URL resource = (new URI(uri + name)).toURL(); FileUtils.copyURLToFile(resource, tmp); } FileUtils.copyFile(tmp, response.getOutputStream()); } catch (Exception ex) { IOUtils.copy(LeaderBoardImagesServlet.class.getResourceAsStream("/unknown.png"), response.getOutputStream()); } }
From source file:api.wiki.WikiNameApi2.java
private TreeMap<String, String> getCategoryOption(String title) { String query = BASE_URL + "&list=categorymembers&cmlimit=500&cmtitle=" + title + "&cmtype=subcat&cmprop=title"; TreeMap<String, String> values = new TreeMap<>(); try {//from w w w . j ava 2 s. com URL url = new URL(query); File file = File.createTempFile("WIKI_", title); FileUtils.copyURLToFile(url, file); String s = FileUtils.readFileToString(file); JSONArray json = new JSONObject(s).getJSONObject("query").getJSONArray("categorymembers"); for (int i = 0; i < json.length(); i++) { String value = json.getJSONObject(i).getString("title"); String key = value.replaceAll("Category:", "").replaceAll("given names", "").trim(); values.put(key, value); } } catch (IOException ex) { Logger.getLogger(WikiNameApi2.class.getName()).log(Level.SEVERE, null, ex); } return values; }
From source file:net.fabricmc.installer.installer.ServerInstaller.java
public static void install(File mcDir, String version, IInstallerProgress progress, File fabricJar) throws IOException { progress.updateProgress(Translator.getString("gui.installing") + ": " + version, 0); String[] split = version.split("-"); String mcVer = split[0];/*from w w w . j a v a 2 s . co m*/ String fabricVer = split[1]; File mcJar = new File(mcDir, "minecraft_server." + mcVer + ".jar"); if (!mcJar.exists()) { progress.updateProgress(Translator.getString("install.server.downloadVersionList"), 10); JsonObject versionList = Utils .loadRemoteJSON(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json")); String url = null; for (JsonElement element : versionList.getAsJsonArray("versions")) { JsonObject object = element.getAsJsonObject(); if (object.get("id").getAsString().equals(mcVer)) { url = object.get("url").getAsString(); break; } } if (url == null) { throw new RuntimeException(Translator.getString("install.server.error.noVersion")); } progress.updateProgress(Translator.getString("install.server.downloadServerInfo"), 12); JsonObject serverInfo = Utils.loadRemoteJSON(new URL(url)); url = serverInfo.getAsJsonObject("downloads").getAsJsonObject("server").get("url").getAsString(); progress.updateProgress(Translator.getString("install.server.downloadServer"), 15); FileUtils.copyURLToFile(new URL(url), mcJar); } File libs = new File(mcDir, "libs"); ZipFile fabricZip = new ZipFile(fabricJar); InstallerMetadata metadata; try (InputStream inputStream = fabricZip .getInputStream(fabricZip.getEntry(Reference.INSTALLER_METADATA_FILENAME))) { metadata = new InstallerMetadata(inputStream); } List<InstallerMetadata.LibraryEntry> fabricDeps = metadata.getLibraries("server", "common"); for (int i = 0; i < fabricDeps.size(); i++) { InstallerMetadata.LibraryEntry dep = fabricDeps.get(i); File depFile = new File(libs, dep.getFilename()); if (depFile.exists()) { depFile.delete(); } progress.updateProgress("Downloading " + dep.getFilename(), 20 + (i * 70 / fabricDeps.size())); FileUtils.copyURLToFile(new URL(dep.getFullURL()), depFile); } progress.updateProgress(Translator.getString("install.success"), 100); }
From source file:net.sourceforge.metware.binche.loader.OfficialChEBIOboLoader.java
/** * The constructor loads the OBO file from the ChEBI ftp and executes the reasoning steps. * * @throws IOException/*from w ww. j a va 2s.c om*/ * @throws BackingStoreException */ public OfficialChEBIOboLoader() throws IOException, BackingStoreException { Preferences binchePrefs = Preferences.userNodeForPackage(BiNChe.class); if (binchePrefs.keys().length == 0) { binchePrefs = (new DefaultPreferenceSetter()).getDefaultSetPrefs(); } PreProcessOboFile ppof = new PreProcessOboFile(); File tmpFileObo = File.createTempFile("BiNChE", ".obo"); FileUtils.copyURLToFile(new URL(oboURL), tmpFileObo); ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(), binchePrefs.get(BiNChEOntologyPrefs.RoleOntology.name(), null), false, true, BiNChEOntologyPrefs.RoleOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label"), new ArrayList<String>()); File tmpRoleOnt = new File(binchePrefs.get(BiNChEOntologyPrefs.RoleOntology.name(), null) + ".temp"); tmpRoleOnt.delete(); ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(), binchePrefs.get(BiNChEOntologyPrefs.StructureOntology.name(), null), false, false, BiNChEOntologyPrefs.StructureOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label", "InChI"), new ArrayList<String>()); File tmpStructOnt = new File(binchePrefs.get(BiNChEOntologyPrefs.StructureOntology.name(), null) + ".temp"); tmpStructOnt.delete(); ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(), binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null), true, true, BiNChEOntologyPrefs.RoleAndStructOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label", "InChI"), Arrays.asList("http://purl.obolibrary.org/obo/RO_0000087")); File tmpStructRoleOnt = new File( binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null) + ".temp"); tmpStructRoleOnt.delete(); File structRoleAnnot = new File( binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null).replace(".obo", ".txt")); String fullPath = binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null); structRoleAnnot.renameTo(new File( fullPath.substring(0, fullPath.lastIndexOf(File.separator)) + File.separator + "chebi_roles.anno")); tmpFileObo.delete(); }
From source file:com.liferay.blade.samples.test.BladeCLIUtil.java
public static String getLatestBladeCLIJar() throws Exception { if (bladeJar == null) { URL url = new URL(System.getProperty("bladeURL")); File file = new File("blade.jar"); FileUtils.copyURLToFile(url, file); Domain jar = Domain.domain(file); int bundleVersion = new Version(jar.getBundleVersion()).getMajor(); if (bundleVersion != 2) { throw new Exception("Expecting bladejar with major version 2, found version: " + bundleVersion); }/*ww w .j av a2 s. com*/ bladeJar = file; } return bladeJar.getCanonicalPath(); }
From source file:com.linkedin.pinot.tools.HybridQuickstart.java
private QuickstartTableRequest prepareOfflineTableRequest() throws IOException { _offlineQuickStartDataDir = new File("quickStartData" + System.currentTimeMillis()); if (!_offlineQuickStartDataDir.exists()) { _offlineQuickStartDataDir.mkdir(); }// w ww . j av a2 s . c o m _offlineQuickStartDataDir = new File("quickStartData" + System.currentTimeMillis()); if (!_offlineQuickStartDataDir.exists()) { _offlineQuickStartDataDir.mkdir(); } File schemaFile = new File(_offlineQuickStartDataDir + "/airlineStats.schema"); File dataFile = new File(_offlineQuickStartDataDir + "/airline.avro"); File tableCreationJsonFileName = new File(_offlineQuickStartDataDir + "/airlineStatsOffline_hybrid.json"); FileUtils.copyURLToFile(Quickstart.class.getClassLoader().getResource("sample_data/airlineStats.schema"), schemaFile); FileUtils.copyURLToFile(Quickstart.class.getClassLoader().getResource("sample_data/airline.avro"), dataFile); FileUtils.copyURLToFile( Quickstart.class.getClassLoader().getResource("sample_data/airlineStatsOffline_hybrid.json"), tableCreationJsonFileName); String tableName = "airlineStats"; return new QuickstartTableRequest(tableName, schemaFile, tableCreationJsonFileName, _offlineQuickStartDataDir, FileFormat.AVRO); }
From source file:net.sourceforge.doddle_owl.utils.Utils.java
public static File getENWNFile() { File wnDir = new File(TEMP_DIR + DODDLEConstants.ENWN_HOME); if (wnDir.exists()) { // System.out.println("exist: " + wnDir.getAbsolutePath()); return wnDir; }//from w ww. jav a2s .c o m wnDir.mkdir(); String[] wnFiles = { "adj.exc", "adv.exc", "cntlist", "cntlist.rev", "data.adj", "data.noun", "data.verb", "frames.vrb", "index.adj", "index.adv", "index.noun", "index.sense", "index.verb", "lexnames", "log.grind.3.0", "noun.exc", "sentidx.vrb", "sents.vrb", "verb.exc", "verb.Framestext" }; for (String wnf : wnFiles) { URL url = DODDLE_OWL.class.getClassLoader().getResource(RESOURCE_DIR + DODDLEConstants.ENWN_HOME + wnf); try { File f = new File(wnDir.getAbsolutePath() + File.separator + wnf); if (url != null) { FileUtils.copyURLToFile(url, f); } // System.out.println("copy: " + f.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } } // System.out.println("created: " + wnDir.getAbsolutePath()); return wnDir; }
From source file:api.behindTheName.BehindTheNameApi.java
private void Search(final HashSet<String> set, int counter, final PeopleNameOption option, final ProgressCallback callback) { final int c = counter; callback.onProgressUpdate(behindTheNameProgressValues[c]); if (!set.isEmpty()) callback.onProgress(new TreeSet<>(set)); Platform.runLater(new Runnable() { @Override//from w w w . j a v a 2 s . co m public void run() { String nation = genres.get(option.genre); String gender = getGenderKey(option.gender); String url = "http://www.behindthename.com/api/random.php?number=6&usage=" + nation + "&gender=" + gender + "&key=" + BEHIND_THE_NAME_KEY; final File file = new File("Temp.xml"); try { URL u = new URL(url); FileUtils.copyURLToFile(u, file); List<String> lines = FileUtils.readLines(file); for (String s : lines) { if (s.contains("<name>")) { s = s.substring(s.indexOf(">") + 1, s.lastIndexOf("</")); set.add(s); } } } catch (MalformedURLException ex) { Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex); } try { Thread.sleep(250); } catch (InterruptedException ex) { Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex); } if (set.size() == MAX_SIZE || c == MAX_SEARCH - 1 || set.isEmpty()) { callback.onProgressUpdate(1.0f); return; } Platform.runLater(new Runnable() { @Override public void run() { Search(set, c + 1, option, callback); } }); } }); }
From source file:cz.cas.lib.proarc.common.process.GenericExternalProcessTest.java
@Test public void testIMConvert() throws Exception { // temp.setDeleteOnExit(false); String imageMagicExec = "/usr/bin/convert"; Assume.assumeTrue(new File(imageMagicExec).exists()); File confFile = temp.newFile("props.cfg"); File root = temp.getRoot();/*from w w w . j a va 2 s . c o m*/ URL pdfaResource = TiffImporterTest.class.getResource("pdfa_test.pdf"); File pdfa = new File(root, "pdfa_test.pdf"); FileUtils.copyURLToFile(pdfaResource, pdfa); FileUtils.writeLines(confFile, Arrays.asList("input.file.name=RESOLVED", "exec=" + imageMagicExec, // "arg=-verbose", "arg=-thumbnail", "arg=120x128", "arg=$${input.file}[0]", "arg=-flatten", "arg=$${output.file}", "id=test")); PropertiesConfiguration conf = new PropertiesConfiguration(confFile); GenericExternalProcess gep = new GenericExternalProcess(conf); gep.addInputFile(pdfa); File output = new File(root, "pdfa.jpg"); gep.addOutputFile(output); gep.run(); // System.out.printf("#exit: %s, out: %s\nresults: %s\n", // gep.getExitCode(), gep.getFullOutput(), gep.getResultParameters()); assertEquals("exit code", 0, gep.getExitCode()); assertTrue(output.toString(), output.exists()); assertTrue("Not JPEG", InputUtils.isJpeg(output)); }