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:com.mgmtp.jfunk.common.util.ExtendedFile.java

/**
 * Copies the specified file. If this object is a directory the file will be copied to this
 * directory. If this object represents a file it will be overwritten with the specified file.
 *///from   ww w  .  j  av  a  2s .c  om
public void copy(final File source) throws IOException {
    if (!source.exists()) {
        LOG.warn("File " + source + " cannot be copied as it does not exist");
        return;
    }
    if (equals(source)) {
        LOG.info("Skipping copying of " + source + " as it matches the target");
        return;
    }
    File target = isDirectory() ? new File(this, source.getName()) : this;
    FileUtils.copyFile(source, target);
}

From source file:com.cy.driver.user.action.ReceiveUploadFileAction.java

private void uploadFile(String path) throws Exception {
    File currFile = new File(path);
    log.info("======>" + currFile.getAbsolutePath());
    FileUtils.copyFile(this.file, currFile);// struts2????   
}

From source file:co.cask.hydrator.plugin.batch.source.ExcelInputReaderTest.java

@Before
public void copyFiles() throws Exception {
    URL testFileUrl = this.getClass().getResource(excelTestFileOne);
    URL testTwofileUrl = this.getClass().getResource(excelTestFileTwo);
    FileUtils.copyFile(new File(testFileUrl.getFile()), new File(sourceFolder, excelTestFileOne));
    FileUtils.copyFile(new File(testTwofileUrl.getFile()), new File(sourceFolder, excelTestFileTwo));
}

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.GenerateXMLFromPropertiesMojo.java

/**
 * <p>/*from   w  w  w.ja  v  a2  s .  c o  m*/
 * First we will copy the XML file extracted from the EAR to the final file
 * to be produced after merging all the properties files.
 * </p>
 * 
 * <p>
 * Then we will initialize the {@link ApplicationType} by unmarshalling
 * this final file.
 * </p>
 * 
 * @throws MojoExecutionException
 */
private void init() throws MojoExecutionException {
    try {
        FileUtils.copyFile(deploymentDescriptor, deploymentDescriptorFinal);
    } catch (IOException e) {
        throw new MojoExecutionException(APPLICATION_MANAGEMENT_COPY_FAILURE + " '" + deploymentDescriptor
                + "' to '" + deploymentDescriptorFinal + "'", e);
    }
    try {
        application = new ApplicationManagement(deploymentDescriptorFinal);
    } catch (JAXBException e) {
        throw new MojoExecutionException(
                APPLICATION_MANAGEMENT_LOAD_FAILURE + " '" + deploymentDescriptorFinal + "'", e);
    }
}

From source file:com.linkedin.gradle.python.tasks.action.pip.PipWheelAction.java

private boolean doesWheelExist(PackageInfo packageInfo) {
    Optional<File> wheel = wheelCache.findWheel(packageInfo.getName(), packageInfo.getVersion(), pythonDetails);
    if (wheel.isPresent()) {
        File wheelFile = wheel.get();

        try {//from   w ww.  j  ava  2s .com
            FileUtils.copyFile(wheelFile, new File(wheelExtension.getWheelCache(), wheelFile.getName()));
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }

        if (PythonHelpers.isPlainOrVerbose(project)) {
            logger.lifecycle("Skipping {}, in wheel cache {}", packageInfo.toShortHand(), wheelFile);
        }
        return true;
    }

    ConfigurableFileTree tree = project.fileTree(wheelExtension.getWheelCache(), action -> {
        String sanitizedName = packageInfo.getName().replace('-', '_');
        String sanitizedVersion = (packageInfo.getVersion() == null ? "unspecified" : packageInfo.getVersion())
                .replace('-', '_');
        action.include("**/" + sanitizedName + "-" + sanitizedVersion + "-*.whl");
    });

    if (tree.getFiles().size() >= 1) {
        logger.lifecycle("Skipping {} wheel - Installed", packageInfo.toShortHand());
        return true;
    }
    return false;
}

From source file:edu.american.student.stonewall.util.Deployer.java

private static void saveResource(File file, File deployDir) throws IOException {
    FileUtils.copyFile(file, new File(deployDir + File.separator + file.getName()));
}

From source file:com.whty.transform.common.utils.TransformUtils.java

public static boolean txtorJavaToPDF(String txtpath) {
    try {//from  w ww . jav  a  2  s . c om
        File pdfPath = new File(SysConf.getString("path.output") + txtpath + "/pdf/");
        String docpath = txtpath.replace(".txt", ".doc").replace(".java", ".doc");
        File tempDoc = new File(SysConf.getString("path.input") + docpath);
        FileUtils.copyFile(new File(SysConf.getString("path.input") + txtpath), tempDoc);
        Document doc = new Document(SysConf.getString("path.input") + docpath);
        if (!pdfPath.exists()) {
            pdfPath.mkdirs();
        }
        doc.save(pdfPath.getAbsolutePath() + "/" + transFileName + ".pdf", SaveFormat.PDF);
        tempDoc.delete();
        return true;
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return false;
}

From source file:com.datatorrent.demos.dimensions.generic.EnrichmentOperatorTest.java

@Test
public void testEnrichmentOperatorWithUpdateKeys() throws IOException, InterruptedException {
    URL origUrl = getClass().getResource("/productmapping.txt");

    URL fileUrl = new URL(getClass().getResource("/").toString() + "productmapping1.txt");
    FileUtils.deleteQuietly(new File(fileUrl.getPath()));
    FileUtils.copyFile(new File(origUrl.getPath()), new File(fileUrl.getPath()));

    EnrichmentOperator oper = new EnrichmentOperator();
    oper.setFilePath(fileUrl.toString());
    oper.setLookupKey("productId");
    oper.setUpdateKeys("subCategory");
    oper.setScanInterval(10);//ww  w. ja va2  s  .co m

    oper.setup(null);
    /* File contains 6 entries, but operator one entry is duplicate,
     * so cache should contains only 5 entries after scanning input file.
     */
    Assert.assertEquals("Number of mappings ", 7, oper.cache.size());

    CollectorTestSink<Map<String, Object>> sink = new CollectorTestSink<Map<String, Object>>();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    CollectorTestSink<Object> tmp = (CollectorTestSink) sink;
    oper.outputPort.setSink(tmp);

    oper.beginWindow(0);
    Map<String, Object> tuple = Maps.newHashMap();
    tuple.put("productId", 7);
    tuple.put("channelId", 4);
    tuple.put("amount", 10.0);

    Kryo kryo = new Kryo();
    oper.inputPort.process(kryo.copy(tuple));

    oper.endWindow();

    /* Number of tuple, emitted */
    Assert.assertEquals("Number of tuple emitted ", 1, sink.collectedTuples.size());
    Map<String, Object> emitted = sink.collectedTuples.iterator().next();

    /* The fields present in original event is kept as it is */
    Assert.assertEquals("Number of fields in emitted tuple", 4, emitted.size());
    Assert.assertEquals("value of productId is 3", tuple.get("productId"), emitted.get("productId"));
    Assert.assertEquals("value of channelId is 4", tuple.get("channelId"), emitted.get("channelId"));
    Assert.assertEquals("value of amount is 10.0", tuple.get("amount"), emitted.get("amount"));

    /* Check if productCategory is added to the event */
    Assert.assertEquals("productCategory is not part of tuple", false, emitted.containsKey("productCategory"));
    Assert.assertEquals("subCategory is part of tuple", true, emitted.containsKey("subCategory"));
    Assert.assertEquals("value of product category is 1", 4, emitted.get("subCategory"));
}

From source file:com.mgmtp.perfload.perfalyzer.util.ArchiveExtracter.java

/**
 * Processes a file. If the file is an archive (zip, tar.gz, tgz), it is extracted to a
 * directory with the name of the archive file. Otherwise, the file is copied to the destination
 * directory./*w  w w .  j  ava 2 s  . co  m*/
 */
@Override
protected void handleFile(final File file, final int depth, final Collection<File> results) throws IOException {
    String fileName = file.getName();

    File targetDir = new File(normalizedDestDirPath, currentNormalizedRelativeDirPath);
    if (!targetDir.exists()) {
        checkState(targetDir.mkdirs(), "Could not create directory: " + targetDir);
    }

    Matcher matcher = ARCHIVE_PATTERN.matcher(fileName);
    if (matcher.find()) {
        log.debug("Extracting file: {}", file);

        try {
            String extension = matcher.group();
            String baseName = StringUtils.substringBeforeLast(fileName, extension);
            Archiver archiver = ArchiverFactory.createArchiver(file);
            archiver.extract(file, new File(targetDir, baseName));
        } catch (IOException ex) {
            log.error("Error extracting file: " + file, ex);
        }
    } else {
        log.debug("Copying file: {}", file);

        // We skip supervisor.log because the Supervisor might be running perfAlyzer
        // and the file could be locked. The file is not needed anyways.
        if (!"supervisor.log".equals(file.getName())) {
            FileUtils.copyFile(file, new File(targetDir, fileName));
        }
    }
}

From source file:net.erdfelt.android.sdkfido.project.maven.MavenOutputProject.java

@Override
public void init() throws FetchException {
    baseDir.ensureExists();//  w  w  w  .  j  a va  2s . com
    sourceDir.ensureExists();
    resourceDir.ensureExists();

    try {
        this.copier = new SourceCopier(baseDir);
    } catch (IOException e) {
        throw new FetchException(e.getMessage(), e);
    }
    if (androidStub != null) {
        try {
            Dir libDir = baseDir.getSubDir("lib");
            libDir.ensureExists();
            FileUtils.copyFile(androidStub, libDir.getFile("android-stub.jar"));
            copier.setNarrowSearchTo(new JarListing(androidStub));
        } catch (IOException e) {
            throw new FetchException(
                    "Unable to narrow search tree by using listing of java files withou android stub jar file: "
                            + androidStub,
                    e);
        }
    }
}