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:org.dmd.mvw.tools.mvwgenerator.doc.web.MvwHtmlDocGenerator.java
public void dumpDocumentation(String od) throws IOException { outdir = od + File.separator + "mvw"; DebugInfo.debug("Generating MVW documentation: " + outdir); Summarizer summary = new Summarizer(defManager, od); initDirs();/*from ww w.j a v a2s. c o m*/ URL url = this.getClass().getResource("mvwstyle.css"); DebugInfo.debug("url: " + url.getFile()); FileUtils.copyURLToFile(url, new File(outdir + File.separator + "mvwstyle.css")); DmcOmni.instance().backRefTracking(true); defManager.prepAggregatedInfo(); for (Module module : defManager.getModules().values()) { ModulePage.dumpModule(outdir, module, summary); } summary.dumpSummaryFiles(); }
From source file:org.domainmath.gui.etc.ResultDialog.java
/** * Check for update. First we download update.xml from sourcefoge,compare with local * update.xml file. If build number is different,try to download update.zip * from sourceforge.//from ww w .j a va2s. c o m */ private void checkUpdate() { File updateDir = new File(System.getProperty("user.dir") + File.separator + "update"); File updateFile = new File( System.getProperty("user.dir") + File.separator + "update" + File.separator + "update.xml"); updateDir.mkdir(); try { // download file update.xml. FileUtils.copyURLToFile(new URL(updateURL), updateFile.getAbsoluteFile()); Update update = getUpdate(new File(System.getProperty("user.dir") + File.separator + "update.xml")); Update update2 = getUpdate(new File( System.getProperty("user.dir") + File.separator + "update" + File.separator + "update.xml")); // compare build number. if (update.getBuildNumber().equals(update2.getBuildNumber())) { Msg msg = new Msg(true); msg.setSecondTitle("DomainMath IDE up to date."); msg.setVisible(true); deleteTemp(updateDir); } else { this.currentVerLabel.setText(update.getVersionName()); this.currentBVerLabel.setText(update.getBuildNumber().toString()); this.newVerLabel.setText(update2.getVersionName()); this.newBVerLabel.setText(update2.getBuildNumber().toString()); this.setVisible(true); } } catch (MalformedURLException ex) { if (displayError) { nerror("Unable to check updates."); } System.err.println("Unable to check updates..."); } catch (IOException ex) { if (displayError) { nerror("Unable to check updates."); } System.err.println("Unable to check updates..."); } dispose(); }
From source file:org.domainmath.gui.etc.ResultDialog.java
/** * Download update from sourceforge.//from www .j av a 2 s . c om */ private void updateDMI() { File updateFile = new File( System.getProperty("user.dir") + File.separator + "update" + File.separator + "update.zip"); try { FileUtils.copyURLToFile(new URL(downloadURL), updateFile.getAbsoluteFile()); msg = new Msg("Update completed.", "Please close DomainMath IDE and double click Update.jar file to complete update process.", true); msg.setVisible(true); MainFrame.statusPanel.changeStatus("Downloading completed."); MainFrame.statusPanel.changeStatus("Get Ready."); thread.interrupt(); String cmd = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java -jar " + System.getProperty("user.dir") + File.separator + "update.jar"; Runtime.getRuntime().exec(cmd); } catch (MalformedURLException ex) { nerror("Unable to download update files.\nPlease check your network connection."); } catch (IOException ex) { nerror("Unable to download update files.\nPlease check your network connection."); } }
From source file:org.dspace.util.SolrImportExport.java
/** * Exports documents from the given index to the specified target directory in batches of #ROWS_PER_FILE, starting at fromWhen (or all documents). * See #makeExportFilename for the file names that are generated. * * @param indexName The index to export. * @param toDir The target directory for the export. Will be created if it doesn't exist yet. The directory must be writeable. * @param solrUrl The solr URL for the index to export. Must not be null. * @param timeField The time field to use for sorting the export. Must not be null. * @param fromWhen Optionally, from when to export. See options for allowed values. If null or empty, all documents will be exported. * @param overwrite If set, allow export files to be overwritten * @throws SolrServerException if there is a problem with exporting the index. * @throws IOException if there is a problem creating the files or communicating with Solr. * @throws SolrImportExportException if there is a problem in communicating with Solr. *//*from ww w. ja v a2s.c o m*/ public static void exportIndex(String indexName, File toDir, String solrUrl, String timeField, String fromWhen, boolean overwrite) throws SolrServerException, IOException, SolrImportExportException { log.info(String.format("Export Index [%s] to [%s] using [%s] Time Field[%s] FromWhen[%s]", indexName, toDir, solrUrl, timeField, fromWhen)); if (StringUtils.isBlank(solrUrl)) { throw new SolrImportExportException( "Could not construct solr URL for index" + indexName + ", aborting export."); } if (!toDir.exists() || !toDir.canWrite()) { throw new SolrImportExportException("Target directory " + toDir + " doesn't exist or is not writable, aborting export of index " + indexName); } HttpSolrServer solr = new HttpSolrServer(solrUrl); SolrQuery query = new SolrQuery("*:*"); if (StringUtils.isNotBlank(fromWhen)) { String lastValueFilter = makeFilterQuery(timeField, fromWhen); if (StringUtils.isNotBlank(lastValueFilter)) { query.addFilterQuery(lastValueFilter); } } query.setRows(0); query.setGetFieldStatistics(timeField); Map<String, FieldStatsInfo> fieldInfo = solr.query(query).getFieldStatsInfo(); if (fieldInfo == null || !fieldInfo.containsKey(timeField)) { log.warn(String.format( "Queried [%s]. No fieldInfo found while exporting index [%s] time field [%s] from [%s]. Export cancelled.", solrUrl, indexName, timeField, fromWhen)); return; } FieldStatsInfo timeFieldInfo = fieldInfo.get(timeField); if (timeFieldInfo == null || timeFieldInfo.getMin() == null) { log.warn(String.format( "Queried [%s]. No earliest date found while exporting index [%s] time field [%s] from [%s]. Export cancelled.", solrUrl, indexName, timeField, fromWhen)); return; } Date earliestTimestamp = (Date) timeFieldInfo.getMin(); query.setGetFieldStatistics(false); query.clearSorts(); query.setRows(0); query.setFacet(true); query.add(FacetParams.FACET_RANGE, timeField); query.add(FacetParams.FACET_RANGE_START, SOLR_DATE_FORMAT.get().format(earliestTimestamp) + "/MONTH"); query.add(FacetParams.FACET_RANGE_END, "NOW/MONTH+1MONTH"); query.add(FacetParams.FACET_RANGE_GAP, "+1MONTH"); query.setFacetMinCount(1); List<RangeFacet.Count> monthFacets = solr.query(query).getFacetRanges().get(0).getCounts(); for (RangeFacet.Count monthFacet : monthFacets) { Date monthStartDate; String monthStart = monthFacet.getValue(); try { monthStartDate = SOLR_DATE_FORMAT_NO_MS.get().parse(monthStart); } catch (java.text.ParseException e) { throw new SolrImportExportException("Could not read start of month batch as date: " + monthStart, e); } int docsThisMonth = monthFacet.getCount(); SolrQuery monthQuery = new SolrQuery("*:*"); monthQuery.setRows(ROWS_PER_FILE); monthQuery.set("wt", "csv"); monthQuery.set("fl", "*"); monthQuery.setParam("csv.mv.separator", MULTIPLE_VALUES_SPLITTER); monthQuery.addFilterQuery(timeField + ":[" + monthStart + " TO " + monthStart + "+1MONTH]"); for (int i = 0; i < docsThisMonth; i += ROWS_PER_FILE) { monthQuery.setStart(i); URL url = new URL(solrUrl + "/select?" + monthQuery.toString()); File file = new File(toDir.getCanonicalPath(), makeExportFilename(indexName, monthStartDate, docsThisMonth, i)); if (file.createNewFile() || overwrite) { FileUtils.copyURLToFile(url, file); String message = String.format( "Solr export to file [%s] complete. Export for Index [%s] Month [%s] Batch [%d] Num Docs [%d]", file.getCanonicalPath(), indexName, monthStart, i, docsThisMonth); log.info(message); } else if (file.exists()) { String message = String.format( "Solr export file [%s] already exists. Export failed for Index [%s] Month [%s] Batch [%d] Num Docs [%d]", file.getCanonicalPath(), indexName, monthStart, i, docsThisMonth); throw new SolrImportExportException(message); } else { String message = String.format( "Cannot create solr export file [%s]. Export failed for Index [%s] Month [%s] Batch [%d] Num Docs [%d]", file.getCanonicalPath(), indexName, monthStart, i, docsThisMonth); throw new SolrImportExportException(message); } } } }
From source file:org.eclipse.smarthome.documentation.GenerateDocumentation.java
/** * Prepares the template directory.// ww w . ja v a 2 s. c o m * <p/> * If needed downloads a set of template files. */ private void prepareTemplateDir() { String[] downloads = { template.replace(".mustache", ""), "partials/bridgeConfig", "partials/bridges", "partials/channelGroupInfo", "partials/channelGroups", "partials/channelInfo", "partials/channels", "partials/config", "partials/configDescriptions", "partials/parameterRow", "partials/paramProperties", "partials/thingConfig", "partials/things" }; // Download all files. for (String url : downloads) { try { // Copy file from URL. String downloadUrl = DOWNLOAD_DIR + url + ".mustache"; String fileName = templates + url + ".mustache"; if (downloadNeeded(fileName)) { getLog().debug("Downloading " + fileName + " from " + downloadUrl); FileUtils.copyURLToFile(new URL(downloadUrl), new File(fileName)); } } catch (MalformedURLException e) { getLog().error(e); } catch (IOException e) { getLog().error(e); } } }
From source file:org.ensor.fftmusings.rnn.GravesLSTMCharModellingExample.java
/** * Downloads Shakespeare training data and stores it locally (temp * directory). Then set up and return a simple DataSetIterator that does * vectorization based on the text./*from w w w . j ava 2s . c o m*/ * * @param miniBatchSize Number of text segments in each training mini-batch * @param exampleLength Number of characters in each text segment. * @param examplesPerEpoch Number of examples we want in an 'epoch'. */ private static CharacterIterator getShakespeareIterator(int miniBatchSize, int exampleLength, int examplesPerEpoch) throws Exception { //The Complete Works of William Shakespeare //5.3MB file in UTF-8 Encoding, ~5.4 million characters //https://www.gutenberg.org/ebooks/100 String url = "https://s3.amazonaws.com/dl4j-distribution/pg100.txt"; String fileLocation = "data/shakespere/Shakespeare.txt"; //Storage location from downloaded file File f = new File(fileLocation); if (!f.exists()) { FileUtils.copyURLToFile(new URL(url), f); System.out.println("File downloaded to " + f.getAbsolutePath()); } else { System.out.println("Using existing text file at " + f.getAbsolutePath()); } if (!f.exists()) { throw new IOException("File does not exist: " + fileLocation); //Download problem? } char[] validCharacters = CharacterIterator.getMinimalCharacterSet(); //Which characters are allowed? Others will be removed return new CharacterIterator(fileLocation, Charset.forName("UTF-8"), miniBatchSize, exampleLength, examplesPerEpoch, validCharacters, new Random(12345), true); }
From source file:org.ensor.fftmusings.rnn2.GravesLSTMCharModellingExample.java
/** * Downloads Shakespeare training data and stores it locally (temp * directory). Then set up and return a simple DataSetIterator that does * vectorization based on the text./*from w w w . j a va 2 s. com*/ * * @param miniBatchSize Number of text segments in each training mini-batch * @param sequenceLength Number of characters in each text segment. */ public static CharacterIterator getShakespeareIterator(int miniBatchSize, int sequenceLength) throws Exception { //The Complete Works of William Shakespeare //5.3MB file in UTF-8 Encoding, ~5.4 million characters //https://www.gutenberg.org/ebooks/100 String url = "https://s3.amazonaws.com/dl4j-distribution/pg100.txt"; String tempDir = System.getProperty("java.io.tmpdir"); String fileLocation = tempDir + "/Shakespeare.txt"; //Storage location from downloaded file File f = new File(fileLocation); if (!f.exists()) { FileUtils.copyURLToFile(new URL(url), f); System.out.println("File downloaded to " + f.getAbsolutePath()); } else { System.out.println("Using existing text file at " + f.getAbsolutePath()); } if (!f.exists()) { throw new IOException("File does not exist: " + fileLocation); //Download problem? } char[] validCharacters = CharacterIterator.getMinimalCharacterSet(); //Which characters are allowed? Others will be removed return new CharacterIterator(fileLocation, Charset.forName("UTF-8"), miniBatchSize, sequenceLength, validCharacters, new Random(12345)); }
From source file:org.everit.osgi.dev.lqmg.test.LQMGTest.java
/** * Testing the normal usage of the LQMG module. *///from w ww. j a v a 2s.c om @Test public void _03_testLQMGGlobalConfiguration() { String tmpDirProperty = "java.io.tmpdir"; String tmpDir = System.getProperty(tmpDirProperty); if (tmpDir == null) { Assert.fail("User temp directory could not be retrieved"); } ClassLoader classLoader = LQMGTest.class.getClassLoader(); URL bundle1URL = classLoader.getResource("META-INF/testBundles/bundle1/"); URL bundle2URL = classLoader.getResource("META-INF/testBundles/bundle2/"); UUID uuid = UUID.randomUUID(); File tmpDirFile = new File(tmpDir); File testDirFile = new File(tmpDirFile, "lqmgtest-" + uuid.toString()); String tempFolderName = testDirFile.getAbsolutePath(); GenerationProperties props = new GenerationProperties("myApp", new String[] { "reference:" + bundle2URL.toExternalForm(), "reference:" + bundle1URL.toExternalForm() }, tempFolderName); props.setPackages(new String[] { "org.everit.osgi.dev.lqmg.test.q2" }); try { File configFile = new File(testDirFile, "config.xml"); URL globalConfigURL = this.getClass().getResource("/META-INF/global.1.lqmg.xml"); FileUtils.copyURLToFile(globalConfigURL, configFile); props.setConfigurationPath(configFile.getAbsolutePath()); LQMG.generate(props); // TODO check if generated classes are ok. } catch (IOException e) { throw new RuntimeException(e); } finally { LQMGTest.deleteFolder(testDirFile); } }
From source file:org.everit.osgi.dev.lqmg.test.LQMGTest.java
/** * Testing the normal usage of the LQMG module. *//*from w w w . j a v a 2s. com*/ @Test public void _04_testConfigInBundles() { String tmpDirProperty = "java.io.tmpdir"; String tmpDir = System.getProperty(tmpDirProperty); if (tmpDir == null) { Assert.fail("User temp directory could not be retrieved"); } ClassLoader classLoader = LQMGTest.class.getClassLoader(); URL bundle1URL = classLoader.getResource("META-INF/testBundles/bundle1/"); URL bundle2URL = classLoader.getResource("META-INF/testBundles/bundle2/"); UUID uuid = UUID.randomUUID(); File tmpDirFile = new File(tmpDir); File testDirFile = new File(tmpDirFile, "lqmgtest-" + uuid.toString()); String tempFolderName = testDirFile.getAbsolutePath(); GenerationProperties props = new GenerationProperties("simpleConfig", new String[] { "reference:" + bundle2URL.toExternalForm(), "reference:" + bundle1URL.toExternalForm() }, tempFolderName); props.setDefaultSchema("org.test"); props.setPackages(new String[] { "org.everit.osgi.dev.lqmg.test.q2" }); try { File configFile = new File(testDirFile, "config.xml"); URL globalConfigURL = this.getClass().getResource("/META-INF/global.2.lqmg.xml"); FileUtils.copyURLToFile(globalConfigURL, configFile); props.setConfigurationPath(configFile.getAbsolutePath()); LQMG.generate(props); // TODO check if generated classes are ok. } catch (IOException e) { throw new RuntimeException(e); } finally { LQMGTest.deleteFolder(testDirFile); } }
From source file:org.everit.osgi.dev.lqmg.test.LQMGTest.java
/** * Testing the normal usage of the LQMG module. *///from w w w . j av a 2 s . com @Test public void _05_testCommandLine() { String tmpDirProperty = "java.io.tmpdir"; String tmpDir = System.getProperty(tmpDirProperty); if (tmpDir == null) { Assert.fail("User temp directory could not be retrieved"); } ClassLoader classLoader = LQMGTest.class.getClassLoader(); URL bundle1URL = classLoader.getResource("META-INF/testBundles/bundle1/"); URL bundle2URL = classLoader.getResource("META-INF/testBundles/bundle2/"); UUID uuid = UUID.randomUUID(); File tmpDirFile = new File(tmpDir); File testDirFile = new File(tmpDirFile, "lqmgtest-" + uuid.toString()); String tempFolderName = testDirFile.getAbsolutePath(); String bundleLocations = "reference:" + bundle2URL.toExternalForm() + ";" + "reference:" + bundle1URL.toExternalForm(); try { File configFile = new File(testDirFile, "config.xml"); URL globalConfigURL = this.getClass().getResource("/META-INF/global.2.lqmg.xml"); FileUtils.copyURLToFile(globalConfigURL, configFile); LQMGMain.main(new String[] { "-cp", "simpleConfig", "-b", bundleLocations, "-c", configFile.getAbsolutePath(), "-p", "org.everit.osgi.dev.lqmg.test.q2", "-o", tempFolderName }); // TODO check if generated classes are ok. } catch (IOException e) { throw new RuntimeException(e); } finally { LQMGTest.deleteFolder(testDirFile); } }