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.kie.wb.test.rest.RestTestBase.java
@BeforeClass public static void createGitRepository() throws GitAPIException, IOException { gitRepository = new File(System.getProperty("user.dir"), "target/git-repository/"); Git git = Git.init().setDirectory(gitRepository).call(); URL pomUrl = RestTestBase.class.getResource("/pom.xml"); File pomFile = new File(gitRepository, "pom.xml"); FileUtils.copyURLToFile(pomUrl, pomFile); git.add().addFilepattern("pom.xml").call(); git.commit().setMessage("Add pom.xml").call(); }
From source file:org.kitesdk.examples.logging.ITLogging.java
@BeforeClass public static void startCluster() throws Exception { File flumeProperties = folder.newFile(); FileUtils.copyURLToFile(Resources.getResource("flume.properties"), flumeProperties); cluster = new Cluster.Builder().addHdfsService().addHiveMetastoreService() .addFlumeAgent("tier1", flumeProperties).build(); cluster.start();/*from w w w . j a va 2 s .c o m*/ Thread.sleep(5000L); configureLog4j(); }
From source file:org.kitodo.selenium.testframework.helper.WebDriverProvider.java
/** * Downloads Geckodriver, extracts archive file and set system property * "webdriver.gecko.driver". On Linux the method also sets executable * permission.//from w w w.j ava2s .com * * @param geckoDriverVersion * The geckodriver version. * @param downloadFolder * The folder in which the downloaded files will be put in. * @param extractFolder * The folder in which the extracted files will be put in. */ public static void provideGeckoDriver(String geckoDriverVersion, String downloadFolder, String extractFolder) throws IOException { String geckoDriverUrl = "https://github.com/mozilla/geckodriver/releases/download/v" + geckoDriverVersion + "/"; String geckoDriverFileName; if (SystemUtils.IS_OS_WINDOWS) { geckoDriverFileName = "geckodriver.exe"; File geckoDriverZipFile = new File(downloadFolder + "geckodriver.zip"); FileUtils.copyURLToFile(new URL(geckoDriverUrl + "geckodriver-v" + geckoDriverVersion + "-win64.zip"), geckoDriverZipFile); extractZipFileToFolder(geckoDriverZipFile, new File(extractFolder)); } else if (SystemUtils.IS_OS_MAC_OSX) { geckoDriverFileName = "geckodriver"; File geckoDriverTarFile = new File(downloadFolder + "geckodriver.tar.gz"); FileUtils.copyURLToFile( new URL(geckoDriverUrl + "geckodriver-v" + geckoDriverVersion + "-macos.tar.gz"), geckoDriverTarFile); File theDir = new File(extractFolder); if (!theDir.exists()) { theDir.mkdir(); } extractTarFileToFolder(geckoDriverTarFile, theDir); } else { geckoDriverFileName = "geckodriver"; File geckoDriverTarFile = new File(downloadFolder + "geckodriver.tar.gz"); FileUtils.copyURLToFile( new URL(geckoDriverUrl + "geckodriver-v" + geckoDriverVersion + "-linux64.tar.gz"), geckoDriverTarFile); extractTarFileToFolder(geckoDriverTarFile, new File(extractFolder)); } File geckoDriverFile = new File(extractFolder, geckoDriverFileName); if (geckoDriverFile.exists()) { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setExecutePermission(geckoDriverFile); } if (geckoDriverFile.canExecute()) { System.setProperty("webdriver.gecko.driver", geckoDriverFile.getPath()); } else { logger.error("Geckodriver not executeable"); } } else { logger.error("Geckodriver file not found"); } }
From source file:org.kitodo.selenium.testframework.helper.WebDriverProvider.java
/** * Downloads chrome driver, extracts archive file and set system property * "webdriver.chrome.driver". On Linux the method also sets executable * permission.//from www . ja v a 2 s. c o m * * @param chromeDriverVersion * The chrome driver version. * @param downloadFolder * The folder in which the downloaded files will be put in. * @param extractFolder * The folder in which the extracted files will be put in. */ public static void provideChromeDriver(String chromeDriverVersion, String downloadFolder, String extractFolder) throws IOException { String chromeDriverUrl = "https://chromedriver.storage.googleapis.com/" + chromeDriverVersion + "/"; String chromeDriverFileName; if (SystemUtils.IS_OS_WINDOWS) { chromeDriverFileName = "chromedriver.exe"; File chromeDriverZipFile = new File(downloadFolder + "chromedriver.zip"); FileUtils.copyURLToFile(new URL(chromeDriverUrl + "chromedriver_win32.zip"), chromeDriverZipFile); extractZipFileToFolder(chromeDriverZipFile, new File(extractFolder)); } else if (SystemUtils.IS_OS_MAC_OSX) { chromeDriverFileName = "chromedriver"; File chromeDriverZipFile = new File(downloadFolder + "chromedriver.zip"); FileUtils.copyURLToFile(new URL(chromeDriverUrl + "chromedriver_mac64.zip"), chromeDriverZipFile); File theDir = new File(extractFolder); if (!theDir.exists()) { theDir.mkdir(); } extractZipFileToFolder(chromeDriverZipFile, new File(extractFolder)); } else { chromeDriverFileName = "chromedriver"; File chromeDriverZipFile = new File(downloadFolder + "chromedriver.zip"); FileUtils.copyURLToFile(new URL(chromeDriverUrl + "chromedriver_linux64.zip"), chromeDriverZipFile); extractZipFileToFolder(chromeDriverZipFile, new File(extractFolder)); } File chromeDriverFile = new File(extractFolder, chromeDriverFileName); if (chromeDriverFile.exists()) { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setExecutePermission(chromeDriverFile); } if (chromeDriverFile.canExecute()) { System.setProperty("webdriver.chrome.driver", chromeDriverFile.getPath()); } else { logger.error("Chromedriver not executeable"); } } else { logger.error("Chromedriver file not found"); } }
From source file:org.knime.ext.textprocessing.dl4j.util.WordVectorPortObjectUtils.java
/** * Copies the content of the specified URL to a temp file. * * @param url/*from w w w.j a v a2 s .c om*/ * @return file pointing to URL content * @throws IOException */ public static File copyURLToTmpFile(final URL url) throws IOException { File tmpFile = FileUtil.createTempFile(UUID.randomUUID().toString(), null); FileUtils.copyURLToFile(url, tmpFile); return tmpFile; }
From source file:org.ktunaxa.referral.server.FileUtil.java
public static void copyURLToFile(URL url, File file) throws IOException { FileUtils.copyURLToFile(url, file); }
From source file:org.lightjason.examples.pokemon.CMain.java
/** * initialization//from w w w . j av a2 s .co m * * @param p_args CLI arguments * @throws IOException on configuration file reading * @throws URISyntaxException on URI sytax definition */ public static void main(final String[] p_args) throws IOException, URISyntaxException { // --- define CLI options ------------------------------------------------------------------------------------------------------------------------------ final Options l_clioptions = new Options(); l_clioptions.addOption("help", false, "shows this information"); l_clioptions.addOption("generate", true, "generates an example configuration within the current directory"); l_clioptions.addOption("configuration", true, "defines the simulation configuration"); final CommandLine l_cli; try { l_cli = new DefaultParser().parse(l_clioptions, p_args); } catch (final Exception l_exception) { System.err.println("command-line arguments parsing error"); System.exit(-1); return; } // --- process CLI arguments and initialize configuration ---------------------------------------------------------------------------------------------- if (l_cli.hasOption("help")) { new HelpFormatter().printHelp( new java.io.File(CMain.class.getProtectionDomain().getCodeSource().getLocation().getPath()) .getName(), l_clioptions); System.exit(0); return; } if (l_cli.hasOption("generate")) { System.exit(Stream.of("agent.asl", "configuration.yaml").parallel().map(i -> { try { FileUtils.copyURLToFile(CCommon.getResourceURL(CCommon.PACKAGEPATH + i), Paths.get(l_cli.getOptionValue("generate", "."), i).normalize().toFile()); return true; } catch (final IOException | URISyntaxException l_exception) { System.err.println(l_exception); return false; } }).allMatch(i -> i) ? 0 : -1); return; } // --- read configuration and initialize simulation ui ------------------------------------------------------------------------------------------------- CConfiguration.INSTANCE.load(l_cli.hasOption("configuration") ? l_cli.getOptionValue("configuration") : CCommon.PACKAGEPATH + "configuration.yaml"); // force-exit must be disabled for avoid error exiting final LwjglApplicationConfiguration l_config = new LwjglApplicationConfiguration(); l_config.forceExit = false; l_config.width = CConfiguration.INSTANCE.windowweight(); l_config.height = CConfiguration.INSTANCE.windowheight(); // open window LOGGER.info(MessageFormat.format("open window with size [{0}x{1}]", l_config.width, l_config.height)); final CScreen l_screen = new CScreen( Stream.concat(CConfiguration.INSTANCE.staticelements().parallelStream(), CConfiguration.INSTANCE.agents().parallelStream()).collect(Collectors.toList()), CConfiguration.INSTANCE.environment(), CConfiguration.INSTANCE.screenshot()); new LwjglApplication(l_screen, l_config); CMain.execute(l_screen); }
From source file:org.locationtech.udig.catalog.teradata.Activator.java
protected static void createPluginStructure(File newPlugin) throws IOException { Bundle teradataLibsBundle = Platform.getBundle(PLUGIN_ID); URL manifest = FileLocator.toFileURL(FileLocator.find(teradataLibsBundle, new Path("License-MANIFEST.MF"), new HashMap<String, String>())); File libsDir = new File(newPlugin, "libs"); libsDir.mkdirs();//w w w . j ava 2 s . co m File metaInf = new File(libsDir.getParentFile(), "META-INF"); FileUtils.copyURLToFile(manifest, new File(metaInf, "MANIFEST.MF")); }
From source file:org.magicbeans.project.setupVisualPanel1.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed URL dlLoc;// www . ja v a 2 s . c o m String url = jTextField1.getText(); char lastChar = url.charAt(url.length() - 1); if (lastChar == '\\' || lastChar == '/') { url = url.substring(0, url.length() - 2); } try { dlLoc = new URL(url); String installerDir = jTextField2.getText(); File toFile = new File(installerDir); if (toFile.exists()) { if (toFile.isDirectory()) { String installerPath = jTextField2.getText() + "/miktexinstaller.exe"; toFile = new File(installerPath); try { FileUtils.copyURLToFile(dlLoc, toFile); Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(installerPath + " -d " + installerDir); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } }
From source file:org.medici.bia.service.peoplebase.PeopleBaseServiceImpl.java
/** * {@inheritDoc}/*from w w w . j a v a 2s .c o m*/ */ @Transactional(readOnly = false, propagation = Propagation.REQUIRED) @Override public BufferedImage savePortaitPerson(PersonPortrait personPortrait) throws ApplicationThrowable { try { People person = getPeopleDAO().find(personPortrait.getPersonId()); if (person != null) { String tempPath = ApplicationPropertyManager.getApplicationProperty("portrait.person.path.tmp"); String portraitPath = ApplicationPropertyManager.getApplicationProperty("portrait.person.path"); File tempFile; String fileName = null; if (personPortrait.getFile() != null && personPortrait.getFile().getSize() > 0) { fileName = personPortrait.getPersonId() + "_" + getCurrentUserName() + "_" + personPortrait.getFile().getOriginalFilename(); tempFile = new File(tempPath + "/" + fileName); FileUtils.writeByteArrayToFile(tempFile, personPortrait.getFile().getBytes()); } else { fileName = personPortrait.getPersonId() + "_" + getCurrentUserName(); String extension = personPortrait.getLink().substring(personPortrait.getLink().lastIndexOf("."), personPortrait.getLink().length()); fileName = fileName.concat(extension); tempFile = new File(tempPath + "/" + fileName); FileUtils.copyURLToFile(new URL(personPortrait.getLink()), tempFile); } File portraitFile = new File(portraitPath + "/" + fileName); if (personPortrait.getFile() != null && personPortrait.getFile().getSize() > 0) { FileUtils.writeByteArrayToFile(portraitFile, personPortrait.getFile().getBytes()); } else { FileUtils.copyFile(tempFile, portraitFile); } person.setPortrait(Boolean.TRUE); person.setPortraitImageName(fileName); person.setLastUpdateBy(getCurrentUser()); person.setLastUpdate(new Date()); getPeopleDAO().merge(person); BufferedImage bufferedImage = ImageIO.read(portraitFile); return bufferedImage; } else { return null; } } catch (Throwable th) { throw new ApplicationThrowable(th); } }