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

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

Introduction

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

Prototype

public static void copyFile(File srcFile, File destFile) throws IOException 

Source Link

Document

Copies a file to a new location preserving the file date.

Usage

From source file:de.qucosa.webapi.v1.FileHandlingService.java

public URI copyTempfileToTargetFileSpace(String tempFilename, String targetName, String qid)
        throws URISyntaxException, IOException {
    File sourceFile = new File(tempfilesPath, tempFilename);
    File targetFile = new File(new File(documentsPath, qid), targetName);
    FileUtils.copyFile(sourceFile, targetFile);
    return targetFile.toURI().normalize();
}

From source file:com.ejisto.util.IOUtils.java

public static String copyFile(File original, File destDir) {
    try {/*  w  w  w. ja  va2  s.c  o m*/
        File copy = new File(destDir, original.getName());
        FileUtils.copyFile(original, copy);
        return copy.getName();
    } catch (IOException e) {
        throw new ApplicationException(e);
    }
}

From source file:co.com.sigemco.alfa.admin.logica.LogoLogica.java

/**
 * Funcion con la cual guardo la imagen en el repositorio de imagenes
 * @return /*  w ww  .  ja v a 2s .  c o  m*/
 */
public String guardaImagenFacturaRepositorio(File file) {
    String rta = "Ok";
    try {
        File nuevoArchivo = new File(this.rutaBase + "logoFact.jpg");
        FileUtils.copyFile(file, nuevoArchivo);
    } catch (Exception e) {
        e.printStackTrace();
        rta = "Error " + e;
    }
    return rta;
}

From source file:net.jsign.PESignerTest.java

public void testSign() throws Exception {
    File sourceFile = new File("target/test-classes/wineyes.exe");
    File targetFile = new File("target/test-classes/wineyes-signed.exe");

    FileUtils.copyFile(sourceFile, targetFile);

    PEFile peFile = new PEFile(targetFile);

    PESigner signer = new PESigner(getKeyStore(), ALIAS, PRIVATE_KEY_PASSWORD).withTimestamping(false)
            .withProgramName("WinEyes").withProgramURL("http://www.steelblue.com/WinEyes");

    signer.sign(peFile);/*from www .  j av a  2 s  .  co  m*/

    peFile = new PEFile(targetFile);
    List<CMSSignedData> signatures = peFile.getSignatures();
    assertNotNull(signatures);
    assertEquals(1, signatures.size());

    CMSSignedData signature = signatures.get(0);

    assertNotNull(signature);
}

From source file:com.comcast.magicwand.drivers.AbstractPhoenixDriver.java

/**
 * Wrapper for {@link FileUtils#copyFile(File, File)}
 *
 * @param src//w  ww  .ja v a  2 s .c  o m
 * @param dst
 * @throws IOException
 */
protected void fileUtilsCopyFile(File src, File dst) throws IOException {
    FileUtils.copyFile(src, dst);
}

From source file:com.zenika.dorm.maven.test.grinder.GrinderGenerateJson.java

public static void generateJsonAndRepository(File repository, File sample, File jsonFile) {
    FileOutputStream outputStream = null;
    try {/* ww w.j av  a2s  .  c  o m*/
        MavenXpp3Writer writer = new MavenXpp3Writer();

        MavenSample sampleJson = getDefaultSample();

        for (int i = 0; i < NUMBER_OF_GENERATED_FILE; i++) {
            MavenPutResource resource = new MavenPutResource();

            File jarFile = new File(repository, "file-" + i + ".jar");
            FileUtils.copyFile(sample, jarFile);
            resource.setJarPath(jarFile.getAbsolutePath());

            File jarFileMd5 = new File(repository, "file-" + i + ".jar.md5");
            generateChecksum(jarFile, jarFileMd5, MD5);
            resource.setJarPathMd5(jarFileMd5.getAbsolutePath());

            File jarFileSha1 = new File(repository, "file-" + i + ".jar.sha1");
            generateChecksum(jarFile, jarFileSha1, SHA1);
            resource.setJarPathSha1(jarFileSha1.getAbsolutePath());

            Model model = generateModel(i);
            File pomFile = new File(repository, "file-" + i + ".pom");
            outputStream = new FileOutputStream(pomFile);
            writer.write(outputStream, model);
            outputStream.close();
            resource.setPomPath(pomFile.getAbsolutePath());

            File pomFileMd5 = new File(repository, "file-" + i + ".pom.md5");
            generateChecksum(pomFile, pomFileMd5, MD5);
            resource.setPomPathMd5(pomFileMd5.getAbsolutePath());

            File pomFileSha1 = new File(repository, "file-i" + i + ".pom.sha1");
            generateChecksum(pomFile, pomFileSha1, SHA1);
            resource.setPomPathSha1(pomFileSha1.getAbsolutePath());

            resource = generateResourceUrl(resource, model);
            sampleJson.getResources().add(resource);
            LOG.info("Files generate with this artifact Id: " + model.getArtifactId());
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.writeValue(jsonFile, sampleJson);
    } catch (IOException e) {
        throw new RuntimeException("Unable to generate file", e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                throw new RuntimeException("Unable to close the Output stream", e);
            }
        }
    }
}

From source file:de.uzk.hki.da.cb.RegisterURNActionTest.java

@Before
public void setUp() throws IOException {
    n.setWorkAreaRootPath(WORK_AREA_ROOT_PATH);

    premis = new DAFile("2012_12_12+12_12_12+a", "premis.xml");
    o.getLatestPackage().getFiles().add(premis);

    FileUtils.copyFile(Path.makeFile(WORK_AREA_ROOT_PATH, "premis.xml.1"), wa.toFile(premis));
    o.setUrn(null);//from   w  ww  . j ava2s  .c  o m
    o.setPackage_type("NONE");
}

From source file:com.samir.commons.java.jarinstallerkit.jarinstaller.JarInstaller.java

public void moveFile(String origin, String destiny) throws Exception {
    LOGGER.log(Level.INFO, String.format("Moving from %s to %s", origin, destiny));

    final File fileOrigin = new File(origin);

    final File fileDestiny = new File(destiny);

    FileUtils.copyFile(fileOrigin, fileDestiny);

    fileOrigin.delete();/*from  w ww. j a  va2  s  .c  o m*/

}

From source file:com.wavemaker.common.util.ClassLoaderUtilsTest.java

public void testTempClassLoader_getResource() throws Exception {

    File sourceJar = new ClassPathResource("com/wavemaker/common/foojar.jar").getFile();
    File jar = File.createTempFile("testTempClassLoader_getClass", ".jar");
    jar.deleteOnExit();/*from w w  w. j a  v a 2 s  .com*/
    FileUtils.copyFile(sourceJar, jar);

    try {
        ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar);
        InputStream is = ClassLoaderUtils.getResourceAsStream("foo/bar/baz/JarType.java", cl);
        assertNotNull(is);
        assertTrue(is.available() > 0);
        is.close();
    } finally {
        jar.delete();
    }
}

From source file:ch.unibas.fittingwizard.mocks.MockBabelScript.java

@Override
public BabelOutput execute(BabelInput input) {

    String moleculeName = getMoleculeName(input.getGaussianLogFile());

    File outputDir = new File(moleculeDestination, moleculeName);

    File outputFile = new File(outputDir, moleculeName + sdfExtension);

    File precomputedDataDir = new File(moleculesTestData, moleculeName);

    for (String fileExtension : filesToCopy) {

        File precomputedFile = new File(precomputedDataDir, moleculeName + fileExtension);

        try {/*w w w.j av a2 s.c om*/
            FileUtils.copyFile(precomputedFile, new File(outputDir, moleculeName + fileExtension));
        } catch (IOException e) {
            logger.error("Could not copy precomputed file " + precomputedFile);
            throw new RuntimeException("Could not copy precomputed file " + precomputedFile);
        }
    }

    return new BabelOutput(outputFile);

}