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:edu.duke.cabig.c3pr.webservice.integration.C3PREmbeddedTomcatTestBase.java

private void prepareTomcatKeystore() throws IOException {
    tomcatKeystore = new File(tmpDir, TOMCAT_KEYSTORE_BASENAME);
    logger.info("Creating " + tomcatKeystore.getCanonicalPath());
    FileUtils.copyURLToFile(
            C3PREmbeddedTomcatTestBase.class.getResource(TESTDATA + "/" + TOMCAT_KEYSTORE_BASENAME),
            tomcatKeystore);//w  w  w. j a  v a2 s. c  o  m

}

From source file:hudson.cli.CLITest.java

License:asdf

@Issue("JENKINS-41745")
@Test//from   w  ww . j a va  2 s  .c om
public void interrupt() throws Exception {
    home = tempHome();
    grabCliJar();

    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    r.jenkins.setAuthorizationStrategy(
            new MockAuthorizationStrategy().grant(Jenkins.ADMINISTER).everywhere().to("admin"));
    SSHD.get().setPort(0);
    File privkey = tmp.newFile("id_rsa");
    FileUtils.copyURLToFile(CLITest.class.getResource("id_rsa"), privkey);
    User.get("admin")
            .addProperty(new UserPropertyImpl(IOUtils.toString(CLITest.class.getResource("id_rsa.pub"))));
    FreeStyleProject p = r.createFreeStyleProject("p");
    p.getBuildersList().add(new SleepBuilder(TimeUnit.MINUTES.toMillis(5)));
    doInterrupt(p, "-remoting", "-i", privkey.getAbsolutePath());
    doInterrupt(p, "-ssh", "-user", "admin", "-i", privkey.getAbsolutePath());
    doInterrupt(p, "-http", "-auth", "admin:admin");
}

From source file:com.github.jarlakxen.embedphantomjs.PhantomJSReference.java

private void downloadPhantomJS(File binaryFile) throws IOException {
    Properties properties = new Properties();
    properties.load(this.getClass().getClassLoader().getResourceAsStream(PHANTOMJS_DATA_FILE));

    String name = properties.getProperty(this.getVersion().getDescription() + "." + this.getHostOs() + ".name");

    String architecture = this.getArchitecture().indexOf("64") >= 0 ? "x86_64" : "i686";

    LOGGER.debug("System Data: Arch [" + architecture + "] - OS [" + this.getHostOs() + "]");

    if (this.getHostOs().equals("linux")) {
        name = String.format(name, architecture);
    }//  w w  w  .j  a  v  a 2 s .  c o  m

    // Download PhantomJS
    URL downloadPath = new URL(this.getDownloadUrl() + name);
    File phantomJsCompressedFile = new File(System.getProperty("java.io.tmpdir") + "/" + name);

    LOGGER.info("Downloading " + downloadPath.getPath() + " ...");

    FileUtils.copyURLToFile(downloadPath, phantomJsCompressedFile);

    ArchiveInputStream archiveInputStream = null;

    if (phantomJsCompressedFile.getName().endsWith(".zip")) {

        archiveInputStream = new ZipArchiveInputStream(new FileInputStream(phantomJsCompressedFile));

    } else if (phantomJsCompressedFile.getName().endsWith(".bz2")) {

        archiveInputStream = new TarArchiveInputStream(
                new BZip2CompressorInputStream(new FileInputStream(phantomJsCompressedFile)));

    } else if (phantomJsCompressedFile.getName().endsWith(".gz")) {

        archiveInputStream = new TarArchiveInputStream(
                new GzipCompressorInputStream(new FileInputStream(phantomJsCompressedFile)));

    }

    ArchiveEntry entry;
    while ((entry = archiveInputStream.getNextEntry()) != null) {
        if (entry.getName().endsWith(PHANTOMJS_DOWNLOAD_BINARY_PATH)
                || entry.getName().toLowerCase().endsWith("phantomjs.exe")) {

            // Create target folder
            new File(this.getTargetInstallationFolder() + "/" + this.getVersion().getDescription()).mkdirs();

            FileUtils.forceMkdir(new File(binaryFile.getParent()));

            if (!binaryFile.exists()) {
                binaryFile.createNewFile();
            }

            binaryFile.setExecutable(true);
            binaryFile.setReadable(true);

            // Untar the binary file
            FileOutputStream outputBinary = new FileOutputStream(binaryFile);

            LOGGER.info("Un-compress download to " + downloadPath.getPath() + " ...");
            IOUtils.copy(archiveInputStream, outputBinary);

            outputBinary.close();
        }
    }

    archiveInputStream.close();
}

From source file:edu.isi.wings.ontapi.jena.KBAPIJena.java

private void readModel() throws Exception {
    if (ontmodel != null) {
        if (this.url != null) {
            try {
                ontmodel.read(this.url);
            } catch (WrappedIOException e) {
                if (this.cache_url) {
                    String furi = LocationMapper.get().altMapping(this.url);
                    FileUtils.copyURLToFile(new URL(this.url), new File(new URI(furi)));
                    ontmodel.read(this.url);
                } else if (this.write_file_if_absent) {
                    this.save();
                    ontmodel.read(this.url);
                } else {
                    System.err.println(this.url + "  not found");
                    //e.printStackTrace();
                }/*from   w ww .j  a va2 s  .  c o  m*/
            }
        } else if (this.inputstream != null) {
            ontmodel.read(this.inputstream, this.base);
        }
    }
}

From source file:com.pwn9.PwnFilter.minecraft.PwnFilterPlugin.java

private void saveDefaultConfig() {
    HashMap<String, String> configFiles = Maps.newHashMap();
    configFiles.put("pwnfilter.conf", "pwnfilter.conf");
    configFiles.put("book.txt", "rules/book.txt");
    configFiles.put("chat.txt", "rules/chat.txt");
    configFiles.put("command.txt", "rules/command.txt");
    configFiles.put("console.txt", "rules/console.txt");
    configFiles.put("item.txt", "rules/item.txt");
    configFiles.put("book.txt", "rules/sign.txt");
    if (!dataFolder.exists()) {
        new File(dataFolder, "rules").mkdirs();
        for (HashMap.Entry<String, String> entry : configFiles.entrySet()) {
            URL url = PwnFilterPlugin.class.getResource(entry.getKey());
            try {
                FileUtils.copyURLToFile(url, new File(dataFolder, entry.getValue()));
            } catch (IOException e) {
                e.printStackTrace();//from w ww  . jav a  2  s . c  om
            }
        }
    }
}

From source file:com.anritsu.mcreleaseportal.tcintegration.ProcessTCRequest.java

public MCPackage extractMCPackage(String changesXMLFileName) throws Exception {
    MCPackage mcp;//from w  ww  .  j  a va2 s  .com
    File dir = new File(Configuration.getInstance().getSavePath());
    if (!dir.isDirectory()) {
        new File(Configuration.getInstance().getSavePath()).mkdirs();
    }
    String fileName = buildName + "_" + buildNumber + "_" + System.currentTimeMillis();
    File file = new File(dir, fileName);
    file.createNewFile();

    FileUtils.copyURLToFile(new URL(artifactsLocation + changesXMLFileName), file);

    pXML = new ProcessChangesXML(file.getAbsolutePath());
    // Check if xml is succesfully validated. If validateXmlXsd() returns an non empty string result code is 1
    result.setResultMessage(pXML.validateXmlXsd());
    if (!result.getResultMessage().replace("Success", "").equalsIgnoreCase("")) {
        result.setResultCode("1");
    }
    mcp = pXML.getMcPackage();
    file.delete();
    return mcp;

}

From source file:com.compomics.pladipus.controller.setup.InstallPladipus.java

private void setupPladipus() throws IOException {
    //1. extract// ww w  . ja  v  a 2  s . c  o  m
    URL inputUrl = getClass().getResource("/Pladipus-execution-" + version + ".zip");
    File dest = new File(pladipusFolder, "Pladipus-execution-" + version + ".zip");
    dest.getParentFile().mkdirs();
    FileUtils.copyURLToFile(inputUrl, dest);
    //2. unzip
    ZipUtils.unzipArchive(dest, pladipusFolder);
    //3. cleanup
    dest.deleteOnExit();
}

From source file:com.github.jengelman.gradle.plugins.integration.TestFile.java

public void copyFrom(URL resource) {
    try {/*  ww  w . j a va 2  s.co m*/
        FileUtils.copyURLToFile(resource, this);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:deincraftlauncher.IO.download.Downloader.java

public static void direectDownload(String Link, String targetFile) {
    try {/*from   w w  w  .jav  a 2s .  com*/
        FileUtils.copyURLToFile(new URL(Link), new File(targetFile));
    } catch (IOException ex) {
        Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:de.appsolve.padelcampus.utils.HtmlResourceUtil.java

private void copyResources(ServletContext context, String sourceFolder, File destinationFolder)
        throws MalformedURLException, IOException {
    Set<String> resourcePaths = context.getResourcePaths(sourceFolder);
    if (resourcePaths == null) {
        LOG.warn(String.format("Unable to find folder %s", sourceFolder));
    } else {//from ww w.  j a va 2  s .  co  m
        for (String resourcePath : resourcePaths) {
            if (resourcePath.endsWith("/")) { //must be a directory
                copyResources(context, resourcePath, destinationFolder);
            } else {
                URL resource = context.getResource(resourcePath);
                FileUtils.copyURLToFile(resource, new File(destinationFolder, resourcePath));
            }
        }
    }
}