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:ca.weblite.codename1.netbeans.Installer.java

private void updateBuildScript() throws IOException {
    URL buildScript = this.getClass().getResource("build-ios-local.xml");
    File projectDir = FileUtil.toFile(project.getProjectDirectory());
    File nbproject = new File(projectDir, "nbproject");
    File buildScriptDest = new File(nbproject, "build-ios-local.xml");
    FileUtils.copyURLToFile(buildScript, buildScriptDest);
}

From source file:au.org.ala.delta.editor.slotfile.model.SlotFileRepositoryTest.java

/**
 * Makes a copy of the supplied DELTA file and returns a new File created from the copied file.
 * @param fileName the ClassLoader relative name of the DELTA file.
 * @return a new File.//  w w  w  . java  2  s  .com
 * @throws IOException if the file cannot be found.
 */
private File copyToTemp(String fileName) throws IOException {

    URL deltaFileUrl = getClass().getResource(fileName);
    File tempDeltaFile = File.createTempFile("SlotFileRepositoryTest", ".dlt");

    FileUtils.copyURLToFile(deltaFileUrl, tempDeltaFile);
    tempDeltaFile.deleteOnExit();

    return tempDeltaFile;
}

From source file:it.iit.genomics.cru.structures.bridges.eppic.client.EppicJaxbClient.java

/**
 *
 * @param pdbId/*from   ww w  . j a v a  2  s  .c  om*/
 * @return
 */
public EppicAnalysisList retrievePDB(String pdbId) {
    String localName = localPath + pdbId + ".xml";
    // is it in local ?

    try {

        File file = new File(localName);
        if (false == file.exists()) {
            // Download it
            URL url = new URL(eppicUrl + pdbId);
            FileUtils.copyURLToFile(url, file);
        }

        return getPdbInterfaces(localName);

    } catch (Exception e) {
        logger.error("Cannot download EPPIC analysis for PDB " + pdbId, e);
        return new EppicAnalysisList();
    }

}

From source file:io.jenkins.plugins.pipelineaction.sources.GlobalRepoPipelineActionTest.java

/**
 * Test//from  ww w .  j ava2  s.  c  o m
 */
@Test
public void actionFromGlobalRepo() throws Exception {
    story.addStep(new Statement() {
        @Override
        public void evaluate() throws Throwable {
            File dir = new File(repo.workspace, "actions/io/jenkins/plugins/pipelineaction/sources");
            dir.mkdirs();

            File outFile = new File(dir, "GlobalRepoDemoAction.groovy");
            FileUtils.copyURLToFile(getClass().getResource(
                    "/io/jenkins/plugins/pipelineaction/sources/GlobalRepoDemoAction.groovy"), outFile);

            // Hack to deal with the lack of an actual commit.
            globalRepoPipelineActionSet.rebuild();
            WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p");

            p.setDefinition(new CpsFlowDefinition("runPipelineAction(['name':'GlobalRepoDemoAction',\n"
                    + "pants:'trousers',\n" + "shirts:'polos'])\n"));

            // get the build going
            WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
            story.j.assertLogContains("echoing pants == trousers",
                    story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
            story.j.assertLogContains("echoing shirts == polos", b);
        }
    });
}

From source file:edu.wustl.cab2b.common.authentication.GTSSynchronizer.java

private static void copyCACertificates(URL inFileURL) {
    int index = inFileURL.getPath().lastIndexOf('/');
    if (index > -1) {
        String fileName = inFileURL.getPath().substring(index + 1).trim();
        File destination = new File(
                gov.nih.nci.cagrid.common.Utils.getTrustedCerificatesDirectory() + File.separator + fileName);

        try {/*from  ww w .j  a  va 2s  .c  o  m*/
            FileUtils.copyURLToFile(inFileURL, destination);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            throw new AuthenticationException(
                    "Unable to copy CA certificates to [user.home]/.globus: " + e.getMessage(), e,
                    ErrorCodeConstants.CDS_003);
        }
    }
}

From source file:blog.attributes.DetectGenderAgeFromFileExample.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(IMAGE_LOCATION), imageFile);
    FileUtils.forceDeleteOnExit(imageFile);
    ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile);
    CognitiveJColourPalette colourPalette = CognitiveJColourPalette.STRAWBERRY;
    List<Face> faces = faceScenarios.findFaces(imageFile);
    faces.forEach(face -> imageOverlayBuilder.outlineFaceOnImage(face, RectangleType.FULL,
            ImageOverlayBuilder.DEFAULT_BORDER_WEIGHT, colourPalette)
            .writeAge(face, colourPalette, RectangleTextPosition.TOP_OF));
    imageOverlayBuilder.launchViewer();/*  w  w  w .  j  av a2 s  .co  m*/

}

From source file:cz.cas.lib.proarc.common.export.mets.JhoveUtilityTest.java

@Test
public void testGetMix() throws Exception {
    File root = temp.getRoot();//from  w w w.ja va  2s. co m
    File imageFile = new File(root, "test.tif");
    //        FileUtils.copyFile(new File("/tmp/test.jp2"),
    //                imageFile, true);
    FileUtils.copyURLToFile(TiffImporterTest.class.getResource("testscan.tiff"), imageFile);
    JHoveOutput output = JhoveUtility.getMix(imageFile, root, null, MetsUtils.getCurrentDate(),
            "testscan.tiff");
    assertNotNull(output);
    Mix mix = output.getMix();
    assertNotNull(mix);

    String toXml = MixUtils.toXml(mix, true);
    //        System.out.println(toXml);
    assertEquals(toXml, "image/tiff",
            mix.getBasicDigitalObjectInformation().getFormatDesignation().getFormatName().getValue());
}

From source file:com.thoughtworks.go.plugin.infra.monitor.AbstractDefaultPluginJarLocationMonitorTest.java

protected void copyPluginToThePluginDirectory(File pluginDir, String destinationFilenameOfPlugin)
        throws IOException, URISyntaxException {
    URL resource = getClass().getClassLoader().getResource("defaultFiles/descriptor-aware-test-plugin.jar");

    FileUtils.copyURLToFile(resource, new File(pluginDir, destinationFilenameOfPlugin));
}

From source file:download.XBRLZipDownloader.java

/**
 * Writes the downloaded file to the hard drive and saves it in the folder structure: date/type/cik.xml
 * @param rssData/*from  w  w w .  jav  a  2s  .co  m*/
 * @throws IOException 
 */
public void downloadXBRLZip(RSSFilingData rssData) throws IOException {
    // gets a system independant file sperator
    String fileSeparator = "" + File.separatorChar;
    // Creates a file path for the output path. The regex reconstructs the format in which
    // the date is represented in the rss data, by removing the day of the month
    // A folder is created for every individual zip file and RSSFilingData object
    String outputPath = XBRLFilePaths.XBRL_FILING_DIRECTORY + fileSeparator
            + rssData.getDate().replaceAll("/([0-9]{2})/", "-") // changes the format of the date to (Month - Year)
            + fileSeparator + rssData.getType() + fileSeparator + rssData.getCik() + fileSeparator
            + rssData.getCik();

    // makes sure the directoris exists in which the file is written to
    validator.validatePath(outputPath);
    // Downloads the zip file and stores it in the given path
    System.out.println(rssData.getURL());
    System.exit(0);
    FileUtils.copyURLToFile(new URL(rssData.getURL()), new File(outputPath + ".zip"));

    System.out.println(outputPath + ".rsd" + "   output path");

    // Saves the rssobjects in the same folder
    saveRSSFilingData(outputPath + ".rsd", rssData);
}

From source file:com.microsoft.azure.hdinsight.util.HDInsightJobViewUtils.java

private static void extractJobViewResource() {
    URL url = HDInsightJobViewUtils.class.getResource("/resources/" + HTML_ZIP_FILE_NAME);
    URL hdinsightJobViewJarUrl = HDInsightJobViewUtils.class
            .getResource("/resources/" + HDINSIGHT_JOB_VIEW_JAR_NAME);
    File indexRootFile = new File(PluginUtil.pluginFolder + File.separator + HTML_FOLDER_NAME);
    if (!indexRootFile.exists()) {
        indexRootFile.mkdir();/*from ww w .j av  a  2 s  . c  om*/
    }
    File toFile = new File(indexRootFile.getAbsolutePath(), HTML_ZIP_FILE_NAME);
    File hdinsightJobViewToFile = new File(indexRootFile.getAbsolutePath(), HDINSIGHT_JOB_VIEW_JAR_NAME);
    try {
        FileUtils.copyURLToFile(url, toFile);
        FileUtils.copyURLToFile(hdinsightJobViewJarUrl, hdinsightJobViewToFile);
        HDInsightJobViewUtils.unzip(toFile.getAbsolutePath(), toFile.getParent());
        DefaultLoader.getIdeHelper().setProperty(HDINSIGHT_JOBVIEW_EXTRACT_FLAG, "true");
    } catch (IOException e) {
        Activator.getDefault().log("Extract Job View Folder", e);
    }
}