Example usage for org.apache.commons.io FileUtils copyURLToFile

List of usage examples for org.apache.commons.io FileUtils copyURLToFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils copyURLToFile.

Prototype

public static void copyURLToFile(URL source, File destination) throws IOException 

Source Link

Document

Copies bytes from the URL source to a file destination.

Usage

From source file:com.roche.iceboar.downloader.FileUtilsFacade.java

public void saveContentFromURLToFile(URL url, File destination) throws IOException {
    FileUtils.copyURLToFile(url, destination);
}

From source file:com.clothcat.rfcreader.network.RfcFetcher.java

private static void fetchIndexSafely(String url) throws FileAlreadyExistsException {
    // TODO handle exceptions better
    File f = new File(Constants.RFC_INDEX_LOCAL_NAME);
    if (f.exists()) {
        throw new FileAlreadyExistsException(f.getAbsolutePath());
    } else {/*from ww w . j ava2 s .co m*/
        try {
            URL u = new URL(url);
            FileUtils.copyURLToFile(u, f);
        } 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:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java

public static String getEth0IPAddress() {
    if (localIP != null) {
        logger.debug("Return local IP address:" + localIP);
        return localIP;
    }/*from   w  w  w . j  a  v  a  2 s.  c  om*/
    // copy the getEth0IPv4 to /tmp and execute it, return the value        
    URL inputUrl = SystemFunctions.class.getResource("/scripts/getEth0IPv4.sh");
    EngineLogger.logger.debug("Search script: " + inputUrl);
    File dest = new File("/tmp/getEth0IPv4.sh");
    try {
        FileUtils.copyURLToFile(inputUrl, dest);
    } catch (IOException ex) {
        EngineLogger.logger
                .error("Cannot create template script file from: " + inputUrl + " to: " + dest.getPath());
    }
    localIP = executeCommandGetOutput("/bin/bash /tmp/getEth0IPv4.sh", "/tmp", null);
    localIP = localIP.trim();
    if (isIPv4Address(localIP)) {
        logger.debug("The {} is IPv4 !", localIP);
        return localIP;
    } else {
        logger.debug("Cannot get IPv4, the command return: {}", localIP);
        localIP = null;
        return "localhost";
    }
}

From source file:com.redhat.rhn.common.conf.test.ConfigTest.java

public void setUp() throws Exception {
    c = new Config();

    // create test config path
    String confPath = "/tmp/" + TestUtils.randomString() + "/conf";
    String defaultPath = confPath + "/default";
    new File(defaultPath).mkdirs();

    // copy test configuration files over
    FileUtils.copyURLToFile(TestUtils.findTestData("conf/rhn.conf"), new File(confPath, "rhn.conf"));
    FileUtils.copyURLToFile(TestUtils.findTestData("conf/default/rhn_web.conf"),
            new File(defaultPath, "rhn_web.conf"));
    FileUtils.copyURLToFile(TestUtils.findTestData("conf/default/rhn_prefix.conf"),
            new File(defaultPath, "rhn_prefix.conf"));
    FileUtils.copyURLToFile(TestUtils.findTestData("conf/default/bug154517.conf.rpmsave"),
            new File(defaultPath, "bug154517.conf.rpmsave"));

    c.addPath(confPath);//from  w  w w  .j av a 2 s.  c  om
    c.addPath(defaultPath);
    c.parseFiles();
}

From source file:io.schultz.dustin.runner.VideoDownloaderLatestRunner.java

@Override
public void run(final ApplicationArguments args) throws Exception {
    final String filename = downloaderProperties.getDownloaderFilename();
    final File fileAbsolute = new File(downloaderProperties.getRootDir(), filename);

    log.info("Downloading latest video downloader to {}", downloaderProperties.getRootDir());
    try {/*from  w  w w.j  a  v  a  2 s.  c om*/
        FileUtils.copyURLToFile(new URL(downloaderProperties.getLatestUrl(), filename), fileAbsolute);
        fileAbsolute.setExecutable(true);
    } catch (IOException e) {
        log.error("Unable to download latest video downloader", e);
    }
    log.info("Finished downloading latest video downloader");
}

From source file:hoot.services.controllers.info.AdvancedOptResourceTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    original_HOME_FOLDER = HOME_FOLDER;//from  w  w  w.  j  ava  2  s.  c om
    homeFolder = new File(FileUtils.getTempDirectory(), "AdvancedOptResourceTest");
    FileUtils.forceMkdir(homeFolder);
    assertTrue(homeFolder.exists());
    HootCustomPropertiesSetter.setProperty("HOME_FOLDER", homeFolder.getAbsolutePath());

    File testFolder = new File(homeFolder, "conf");
    FileUtils.forceMkdir(testFolder);

    File dest = new File(testFolder, "services/conflationRefOps.json");
    URL inputUrl = AdvancedOptResourceTest.class
            .getResource("/hoot/services/controllers/info/conflationRefOps.json");
    FileUtils.copyURLToFile(inputUrl, dest);

    dest = new File(testFolder, "services/conflateAdvOps.json");
    inputUrl = AdvancedOptResourceTest.class.getResource("/hoot/services/controllers/info/conflateAdvOps.json");
    FileUtils.copyURLToFile(inputUrl, dest);

    dest = new File(testFolder, "services/conflationAverageOps.json");
    inputUrl = AdvancedOptResourceTest.class
            .getResource("/hoot/services/controllers/info/conflationAverageOps.json");
    FileUtils.copyURLToFile(inputUrl, dest);

    dest = new File(testFolder, "services/conflationHorizontalOps.json");
    inputUrl = AdvancedOptResourceTest.class
            .getResource("/hoot/services/controllers/info/conflationHorizontalOps.json");
    FileUtils.copyURLToFile(inputUrl, dest);

    dest = new File(testFolder, "core/ConfigOptions.asciidoc");
    inputUrl = AdvancedOptResourceTest.class
            .getResource("/hoot/services/controllers/info/ConfigOptions.asciidoc");
    FileUtils.copyURLToFile(inputUrl, dest);
}

From source file:com.cloudbees.plugins.credentials.impl.CertificateCredentialsImplTest.java

@Test
public void displayName() throws Exception {
    File p12 = tmp.newFile("test.p12");
    FileUtils.copyURLToFile(CertificateCredentialsImplTest.class.getResource("test.p12"), p12);
    assertEquals("EMAILADDRESS=me@myhost.mydomain, CN=pkcs12, O=Fort-Funston, L=SanFrancisco, ST=CA, C=US",
            CredentialsNameProvider.name(new CertificateCredentialsImpl(null, "abc123", null, "password",
                    new CertificateCredentialsImpl.FileOnMasterKeyStoreSource(p12.getAbsolutePath()))));
}

From source file:core.GenerateYamlTest.java

@Test
public void generateYAML() throws IOException {
    final int localPort = RULE.getLocalPort();
    final String swagger_filename = "/swagger.yaml";
    File destination = new File(System.getProperty("baseDir") + "/src/main/resources/", "swagger.yaml");
    final URL url = new URL("http", "localhost", localPort, swagger_filename);
    System.out.println(url.toString());
    FileUtils.copyURLToFile(url, destination);
}

From source file:cloudnet.weather.data.forecastio.WeatherDataFetcher.java

public void fetchData(String locationData, String city, Calendar start, Calendar end) {

    try {/*from  w  w w. j av  a  2 s .c  om*/
        URL url;
        while (start.before(end)) {
            url = new URL(urlString + locationData + "," + start.getTimeInMillis() / 1000 + "?units=si");
            File file = new File("resources/weather/" + city + "/" + start.getTimeInMillis() / 1000 + ".json");
            LOGGER.trace("downloading " + start.getTimeInMillis() / 1000);
            FileUtils.copyURLToFile(url, file);
            start.add(Calendar.HOUR, 12);
        }

    } catch (MalformedURLException e) {
        LOGGER.error("fetchData", e);
    } catch (IOException e) {
        LOGGER.error("fetchData", e);
    }
}

From source file:com.sonarsource.cobol.ebcdic.MainTest.java

@Test
public void should_convert_all_files_in_directory_and_sub_directories() throws Exception {
    URL ebcdicSource = FileConverterTest.class.getResource("/EBCDIC.txt");
    File expectedOutputFile = new File(FileConverterTest.class.getResource("/ASCII.txt").toURI());

    File source = tempFolder.newFolder();
    File destination = tempFolder.newFolder();
    File inputFile1 = new File(source, "cobol.txt");
    File outputFile1 = new File(destination, "cobol.txt");
    FileUtils.copyURLToFile(ebcdicSource, inputFile1);
    File inputFile2 = new File(source, "sub/cobol.txt");
    File outputFile2 = new File(destination, "sub/cobol.txt");
    FileUtils.copyURLToFile(ebcdicSource, inputFile2);
    File inputFile3 = new File(source, "sub/sub/cobol.txt");
    File outputFile3 = new File(destination, "sub/sub/cobol.txt");
    FileUtils.copyURLToFile(ebcdicSource, inputFile3);

    String[] args = new String[] { "-f", "CP1047", "-t", "UTF-8", "-l", "80", source.getAbsolutePath(),
            destination.getAbsolutePath() };
    Main.main(args);//from  w  w  w  . j  ava  2  s  .  com

    assertThat(FileUtils.contentEquals(outputFile1, expectedOutputFile)).isTrue();
    assertThat(FileUtils.contentEquals(outputFile1, inputFile1)).isFalse();
    assertThat(FileUtils.contentEquals(outputFile2, expectedOutputFile)).isTrue();
    assertThat(FileUtils.contentEquals(outputFile2, inputFile2)).isFalse();
    assertThat(FileUtils.contentEquals(outputFile3, expectedOutputFile)).isTrue();
    assertThat(FileUtils.contentEquals(outputFile2, inputFile2)).isFalse();
}