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:cz.cas.lib.proarc.common.workflow.FilterFindParameterQueryTest.java
@Before public void setUp() throws Exception { File xmlWorkflow = temp.newFile("workflowTest.xml"); FileUtils.copyURLToFile(WorkflowManagerTest.class.getResource("WorkflowManagerAddProfile.xml"), xmlWorkflow);//from ww w . ja va2s .c o m WorkflowProfiles.setInstance(new WorkflowProfiles(xmlWorkflow)); wp = WorkflowProfiles.getInstance(); }
From source file:eu.linda.analytics.formats.RDFInputFormat.java
@Override public AbstractList importData4weka(String query_id, boolean isForRDFOutput, Analytics analytics) { String queryURI = connectionController.getQueryURI(query_id); helpfulFunctions.nicePrintMessage("import data from uri " + queryURI); Instances data = null;//from w w w . j a v a 2 s . c om try { float timeToGetQuery = 0; long startTimeToGetQuery = System.currentTimeMillis(); URL url = new URL(queryURI); if (!helpfulFunctions.isURLResponsive(url)) { return null; } File tmpfile4lindaquery = File.createTempFile("tmpfile4lindaquery" + query_id, ".tmp"); FileUtils.copyURLToFile(url, tmpfile4lindaquery); System.out.println("Downloaded File Query: " + tmpfile4lindaquery); CSVLoader loader = new CSVLoader(); loader.setSource(tmpfile4lindaquery); if (isForRDFOutput) { loader.setStringAttributes("1,2"); } loader.setFieldSeparator(","); data = loader.getDataSet(); data.setClassIndex(data.numAttributes() - 1); FileInputStream fis = null; try { fis = new FileInputStream(tmpfile4lindaquery); System.out.println("fis.getChannel().size() " + fis.getChannel().size()); analytics.setData_size(analytics.getData_size() + fis.getChannel().size()); } finally { fis.close(); } // Get elapsed time in milliseconds long elapsedTimeToGetQueryMillis = System.currentTimeMillis() - startTimeToGetQuery; // Get elapsed time in seconds timeToGetQuery = elapsedTimeToGetQueryMillis / 1000F; analytics.setTimeToGet_data(analytics.getTimeToGet_data() + timeToGetQuery); System.out.println("timeToGetQuery" + timeToGetQuery); connectionController.updateLindaAnalyticsInputDataPerformanceTime(analytics); } catch (Exception ex) { Logger.getLogger(ArffInputFormat.class.getName()).log(Level.SEVERE, null, ex); } return data; }
From source file:cz.cas.lib.proarc.common.workflow.profile.WorkflowProfiles.java
/** * Creates a new workflow definition file if not exists. * @param target/*from w w w . ja v a2 s . c om*/ * @throws IOException error */ public static void copyDefaultFile(File target) throws IOException { if (target.exists()) { return; } FileUtils.copyURLToFile(WorkflowProfiles.class.getResource("workflow.xml"), target); }
From source file:minecrunch_launcher.Server.java
public void run() { // Install selected server if (os.contains("Windows")) { minecrunchDir = home + "\\minecrunch\\"; } else {/*from ww w . j av a 2s . c o m*/ minecrunchDir = home + "/minecrunch/"; } wd.setVisible(true); // create directory in users home folder server File dir = new File(minecrunchDir + name + "_server"); if (!dir.exists()) { if (dir.mkdir()) { String console = "Server directory created."; System.out.println(console); } else { String console = "Server directory already exists."; System.out.println(console); } } // download file from server URL url = null; try { url = new URL("http://www.minecrunch.net/download/" + name + "/server_install.zip"); } catch (MalformedURLException ex) { System.out.println(ex); } File file = new File(minecrunchDir + "server_install.zip"); try { FileUtils.copyURLToFile(url, file); } catch (IOException ex) { System.out.println(ex); } // unzip file in users home folder and extract it to server try { ZipFile zipFile = new ZipFile(minecrunchDir + "server_install.zip"); zipFile.extractAll(minecrunchDir + name + "_server"); } catch (ZipException e) { } File dir2 = new File(minecrunchDir + name + "_server\\server_install"); File dir3 = new File(minecrunchDir + name + "_server"); try { FileUtils.copyDirectory(dir2, dir3); FileUtils.deleteDirectory(dir2); } catch (IOException ex) { System.out.println(ex); } // clean up and delete zip file that was downloaded file.delete(); wd.setVisible(false); }
From source file:hudson.PluginManagerTest.java
/** * Manual submission form.//from ww w .jav a 2 s.c o m */ public void testUpload() throws Exception { HtmlPage page = new WebClient().goTo("pluginManager/advanced"); HtmlForm f = page.getFormByName("uploadPlugin"); File dir = env.temporaryDirectoryAllocator.allocate(); File plugin = new File(dir, "tasks.hpi"); FileUtils.copyURLToFile(getClass().getClassLoader().getResource("plugins/tasks.hpi"), plugin); f.getInputByName("name").setValueAttribute(plugin.getAbsolutePath()); submit(f); assertTrue(new File(hudson.getRootDir(), "plugins/tasks.hpi").exists()); }
From source file:ddf.services.schematron.SchematronValidationServiceTest.java
@Before public void setup() throws IOException { URL src = SchematronValidationServiceTest.class.getClassLoader().getResource("dog_legs.sch"); fileWithSpaces = Paths.get(testFolder.getRoot().getAbsolutePath()).resolve("folder with spaces") .resolve("dog_legs.sch").toFile(); FileUtils.copyURLToFile(src, fileWithSpaces); }
From source file:au.org.ala.delta.DeltaTestCase.java
/** * Makes a copy of the supplied DELTA file and returns a new SlotFile created from the copied file. * @param fileName the ClassLoader relative name of the DELTA file. * @return a new SlotFile./* ww w . j a va 2 s . c o m*/ * @throws IOException if the file cannot be found. */ protected SlotFile copyAndOpen(String fileName) throws IOException { URL deltaFileUrl = getClass().getResource(fileName); File tempDeltaFile = File.createTempFile("test", ".dlt"); _tempFiles.add(tempDeltaFile); FileUtils.copyURLToFile(deltaFileUrl, tempDeltaFile); SlotFile slotFile = new SlotFile(tempDeltaFile.getAbsolutePath(), BinFileMode.FM_EXISTING); return slotFile; }
From source file:blog.detect.DetectSingleFaceFromFileExample.java
public static void main(String[] args) throws IOException { FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"), System.getProperty("azure.cognitive.emotion.subscriptionKey")); File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic"); //create a new java.io.File from a remote file FileUtils.copyURLToFile(new URL(FILE_LOCATION_OF_US_PRESIDENT), imageFile); FileUtils.forceDeleteOnExit(imageFile); ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile); imageOverlayBuilder.outlineFaceOnImage(faceScenarios.findSingleFace(imageFile), RectangleType.FULL) .launchViewer();/*from w w w.j a va 2 s . c o m*/ }
From source file:com.linkedin.pinot.tools.RealtimeQuickStart.java
public void execute() throws JSONException, Exception { _quickStartDataDir = new File("quickStartData" + System.currentTimeMillis()); String quickStartDataDirName = _quickStartDataDir.getName(); if (!_quickStartDataDir.exists()) { _quickStartDataDir.mkdir();/* w w w .j av a 2s .co m*/ } File schema = new File(quickStartDataDirName + "/rsvp_pinot_schema.json"); File tableCreate = new File(quickStartDataDirName + "/rsvp_create_table_request.json"); FileUtils.copyURLToFile( RealtimeQuickStart.class.getClassLoader().getResource("sample_data/rsvp_pinot_schema.json"), schema); FileUtils.copyURLToFile( RealtimeQuickStart.class.getClassLoader().getResource("sample_data/rsvp_create_table_request.json"), tableCreate); printStatus(color.CYAN, "Starting Kafka"); _zookeeperInstance = ZkStarter.startLocalZkServer(); final KafkaServerStartable kafkaStarter = KafkaStarterUtils.startServer( KafkaStarterUtils.DEFAULT_KAFKA_PORT, KafkaStarterUtils.DEFAULT_BROKER_ID, KafkaStarterUtils.DEFAULT_ZK_STR, KafkaStarterUtils.getDefaultKafkaConfiguration()); KafkaStarterUtils.createTopic("meetupRSVPEvents", KafkaStarterUtils.DEFAULT_ZK_STR, 10); File tempDir = new File("/tmp/" + String.valueOf(System.currentTimeMillis())); QuickstartTableRequest request = new QuickstartTableRequest("meetupRsvp", schema, tableCreate); final QuickstartRunner runner = new QuickstartRunner(Lists.newArrayList(request), 1, 1, 1, tempDir); runner.startAll(); printStatus(color.CYAN, "Starting controller, server and broker"); runner.addSchema(); runner.addTable(); printStatus(color.CYAN, "Added schema and table"); printStatus(color.YELLOW, "Realtime quickstart setup complete"); final MeetupRsvpStream meetupRSVPProvider = new MeetupRsvpStream(schema); meetupRSVPProvider.run(); printStatus(color.CYAN, "Starting meetup data stream and publishing to kafka"); // lets wait for a few events to get populated Thread.sleep(5000); String q1 = "select count(*) from meetupRsvp limit 0"; printStatus(color.YELLOW, "Total number of documents in the table"); printStatus(color.CYAN, "Query : " + q1); printStatus(color.YELLOW, prettyprintResponse(runner.runQuery(q1))); printStatus(color.GREEN, "***************************************************"); String q2 = "select sum(rsvp_count) from meetupRsvp group by group_city top 10 limit 0"; printStatus(color.YELLOW, "Top 10 cities with the most rsvp"); printStatus(color.CYAN, "Query : " + q2); printStatus(color.YELLOW, prettyprintResponse(runner.runQuery(q2))); printStatus(color.GREEN, "***************************************************"); String q3 = "select * from meetupRsvp order by mtime limit 10"; printStatus(color.YELLOW, "Show 10 most recent rsvps"); printStatus(color.CYAN, "Query : " + q3); printStatus(color.YELLOW, prettyprintResponse(runner.runQuery(q3))); printStatus(color.GREEN, "***************************************************"); String q4 = "select sum(rsvp_count) from meetupRsvp group by event_name top 10 limit 0"; printStatus(color.YELLOW, "Show top 10 rsvp'ed events"); printStatus(color.CYAN, "Query : " + q4); printStatus(color.YELLOW, prettyprintResponse(runner.runQuery(q4))); printStatus(color.GREEN, "***************************************************"); String q5 = "select count(*) from meetupRsvp limit 0"; printStatus(color.YELLOW, "Total number of documents in the table"); printStatus(color.CYAN, "Query : " + q5); printStatus(color.YELLOW, prettyprintResponse(runner.runQuery(q5))); printStatus(color.GREEN, "***************************************************"); printStatus(color.GREEN, "you can always go to http://localhost:9000/query/ to play around in the query console"); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { printStatus(color.GREEN, "***** shutting down realtime quickstart *****"); meetupRSVPProvider.stopPublishing(); FileUtils.deleteDirectory(_quickStartDataDir); runner.stop(); runner.clean(); KafkaStarterUtils.stopServer(kafkaStarter); ZkStarter.stopLocalZkServer(_zookeeperInstance); } catch (Exception e) { e.printStackTrace(); } } }); long st = System.currentTimeMillis(); while (true) { if (System.currentTimeMillis() - st >= (60 * 60) * 1000) { break; } } printStatus(color.YELLOW, "running since an hour, stopping now"); }
From source file:com.canoo.webtest.util.WebtestEmbeddingUtil.java
/** * Copies WebTest resources (ie webtest.xml, tools/*, the XSLs, CSSs and pictures, ...) package in WebTest jar file * into the provide folder. Indeed different Ant tasks can't work with resources in a jar file. * @param targetFolder the folder in which resources should be copied to * @throws java.io.IOException if the resources can be accessed or copied *///from w ww . jav a2 s.c o m static void copyWebTestResources(final File targetFolder) throws IOException { final String resourcesPrefix = "com/canoo/webtest/resources/"; final URL webtestXmlUrl = WebtestEmbeddingUtil.class.getClassLoader() .getResource(resourcesPrefix + "webtest.xml"); if (webtestXmlUrl == null) { throw new IllegalStateException("Can't find resource " + resourcesPrefix + "webtest.xml"); } else if (webtestXmlUrl.toString().startsWith("jar:file")) { final String urlJarFileName = webtestXmlUrl.toString().replaceFirst("^jar:file:([^\\!]*).*$", "$1"); final String jarFileName = URLDecoder.decode(urlJarFileName, Charset.defaultCharset().name()); final JarFile jarFile = new JarFile(jarFileName); final String urlPrefix = StringUtils.removeEnd(webtestXmlUrl.toString(), "webtest.xml"); for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { final JarEntry jarEntry = entries.nextElement(); if (jarEntry.getName().startsWith(resourcesPrefix)) { final String relativeName = StringUtils.removeStart(jarEntry.getName(), resourcesPrefix); final URL url = new URL(urlPrefix + relativeName); final File targetFile = new File(targetFolder, relativeName); FileUtils.forceMkdir(targetFile.getParentFile()); FileUtils.copyURLToFile(url, targetFile); } } } else if (webtestXmlUrl.toString().startsWith("file:")) { // we're probably developing and/or have a custom version of the resources in classpath final File webtestXmlFile = FileUtils.toFile(webtestXmlUrl); final File resourceFolder = webtestXmlFile.getParentFile(); FileUtils.copyDirectory(resourceFolder, targetFolder); } else { throw new IllegalStateException( "Resource " + resourcesPrefix + "webtest.xml is not in a jar file: " + webtestXmlUrl); } }