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

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

Introduction

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

Prototype

public static void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate)
        throws IOException 

Source Link

Document

Copies a file to a directory optionally preserving the file date.

Usage

From source file:alilibs.AliFile.java

public static void copyfile(String urldir, File f) throws Exception {
    FileUtils.copyFileToDirectory(f, new File(urldir), true);
}

From source file:com.github.rinde.gpem17.Train.java

static void run(String configFile) {
    AvoidExitUtil.forbidSystemExitCall();
    try {//w  w w  .j  av  a2  s . c om
        Evolve.main(new String[] { "-file", configFile });
    } catch (ExitTrappedException e) {
    } finally {
        AvoidExitUtil.enableSystemExitCall();
    }
    File f = new File("nohup.out");
    if (f.exists()) {
        try {
            FileUtils.copyFileToDirectory(f, new File("files/results/evo/latest"), false);

            Files.write("", f, Charsets.UTF_8);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}

From source file:com.puzzle.module.send.excutor.MessageSendExcutor.java

public void excute(File xml) {
    KafkaProducerClient client = null;//from w w  w .ja  v a2 s  .c  om

    try {
        String content = FileUtils.readFileToString(xml, "UTF-8");

        XmlCheckResult checkResult = xmlCheck.isValid(content);
        if (!checkResult.isValid) {//

            FileUtils.copyFileToDirectory(xml, new File(FileDto.getSingleInstance().errorPath), true);

            log.error(xml.getAbsolutePath() + "");
            return;
        }

        boolean tr = true;
        if (content.indexOf("<CEB625Message") != -1 || content.indexOf("<CEB623Message") != -1
                || content.indexOf("<CEB711Message") != -1 || content.indexOf("<CEB513Message") != -1) {//?

            String signedXml = SignXml.sign2(content);
            if (signedXml == null || signedXml.equals("")) {
                return;
            }

            File signFile = new File(FileDto.getSingleInstance().fileSignPath,
                    "???-" + DateUtil.getCurrDateMM2() + xml.getName());
            FileUtils.writeStringToFile(signFile, signedXml, "UTF-8");
            if (FileDto.getSingleInstance().sendCusisSelected) {
                client = KafkaProducerClient.getSingletonInstance();
                client.send(FileDto.getSingleInstance().cusSendTopic, signedXml);
                QueueUtils.sendSignTable.offer(new JtableMessageDto(signFile.getAbsolutePath(),
                        DateUtil.getFormatDateTime(new Date())));

                log.info(xml.getName() + "???");
            }

        } else {

            String splitXml = SpliteXml.splite(content);

            if (splitXml == null) {
                return;
            }
            log.info(xml.getName() + "");

            splitXml = SignXml.sign(splitXml);// ????

            if (splitXml == null) {
                log.info("?>>>>??");
                return;
            }

            File signFile = new File(FileDto.getSingleInstance().fileSignPath,
                    "???-" + DateUtil.getCurrDateMM2() + xml.getName());
            FileUtils.writeStringToFile(signFile, splitXml, "UTF-8");

            //          

            if (FileDto.getSingleInstance().sendCusisSelected) {
                client = KafkaProducerClient.getSingletonInstance();
                client.send(FileDto.getSingleInstance().cusSendTopic, splitXml);
                QueueUtils.sendSignTable.offer(new JtableMessageDto(signFile.getAbsolutePath(),
                        DateUtil.getFormatDateTime(new Date())));

                log.info(xml.getName() + "???");
            }

            if (FileDto.getSingleInstance().sendCiqisSelected) {
                client = KafkaProducerClient.getSingletonInstance();
                client.send(FileDto.getSingleInstance().sendTpoic, content);//??? 
                QueueUtils.sendTable1.offer(
                        new JtableMessageDto(xml.getAbsolutePath(), DateUtil.getFormatDateTime(new Date())));

                log.info(xml.getName() + "???");
            }

        }

    } catch (Exception e) {
        e.printStackTrace();
        if (client != null) {
            client.close();
        }
    }

}

From source file:de.uzk.hki.da.pkg.ZipArchiveBuilder.java

/**
 * WARN this is actually implemented with /usr/bin/jar instead of /usr/bin/unzip.
 * See implementation notes at {@link de.uzk.hki.da.pkg.ArchiveBuilder#unarchiveFolder(File, File)}.
 *//* w w  w.  j  ava  2s .  c om*/
public void unarchiveFolder(File srcTar, File destFolder) throws Exception {

    logger.debug("moving {} to folder {}", srcTar, destFolder);
    FileUtils.copyFileToDirectory(srcTar, destFolder, false);

    ProcessInformation pi = new CommandLineConnector().runCmdSynchronously(
            new String[] { "/usr/bin/jar", "-xf", FilenameUtils.getName(srcTar.getAbsolutePath()) }, destFolder,
            0);

    if ((pi == null) || (pi.getExitValue() != 0)) {
        if (pi != null)
            logger.error(pi.getStdErr());
        throw new RuntimeException("Couldnt unpack package");
    }

    new File(destFolder.getAbsolutePath() + "/" + FilenameUtils.getName(srcTar.getAbsolutePath())).delete();
}

From source file:edu.purdue.cybercenter.dm.web.GlobusControllerTest.java

public static void setUpClass() throws Exception {
    File source1 = new File("./src/test/files/" + FILE_TO_UPLOAD_1);
    File source2 = new File("./src/test/files/" + FILE_TO_UPLOAD_2);
    File source3 = new File("./src/test/files/" + FILE_TO_DOWNLOAD_1);

    String remoteEndpointDir = STORAGE_ROOT + REMOTE_ENDPOINT;
    File destDir = new File(remoteEndpointDir);

    FileUtils.copyFileToDirectory(source1, destDir, true);
    FileUtils.copyFileToDirectory(source2, destDir, true);

    String storageDir = STORAGE_ROOT + GLOBUS_STORAGE_DIRECTORY;
    destDir = new File(storageDir);

    if (destDir.exists() && destDir.isDirectory()) {
        FileUtils.copyFileToDirectory(source3, destDir, true);
    }/*from   ww w  .j  a va2s.  c o  m*/

    FileUtils.cleanDirectory(new File(STORAGE_ROOT + GLOBUS_STORAGE_WORKEAERA_DIRECTORY));
}

From source file:com.carolinarollergirls.scoreboard.xml.AutoSaveScoreBoard.java

protected void backupAutoSavedFiles() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    File mainBackupDir = new File(new File(ScoreBoardManager.getDefaultPath(), DIRECTORY_NAME), "backup");
    File backupDir = new File(mainBackupDir, dateFormat.format(new Date()));
    if (backupDir.exists()) {
        ScoreBoardManager.printMessage("Could not back up auto-save files, backup directory already exists");
    } else {/*from   ww  w.j a v  a 2s. c  o  m*/
        int n = 0;
        do {
            File from = getFile(n);
            if (from.exists()) {
                try {
                    FileUtils.copyFileToDirectory(from, backupDir, true);
                    ScoreBoardManager.printMessage(
                            "Copied auto-save file " + from.getName() + " to " + backupDir.getPath());
                } catch (Exception e) {
                    ScoreBoardManager.printMessage(
                            "Could not back up auto-save file '" + from.getName() + "' : " + e.getMessage());
                }
            }
        } while (n++ < AUTOSAVE_FILES);
    }
}

From source file:fr.acxio.tools.agia.io.AbstractFileOperations.java

protected void copyFile(Resource sOriginFile, Resource sDestinationFile) throws IOException {
    File aOrigineFile = sOriginFile.getFile();
    if (aOrigineFile.isFile()) {
        if (!isDirectory(sDestinationFile)) {
            FileUtils.copyFile(aOrigineFile, sDestinationFile.getFile(), preserveAttributes);
        } else {//w w  w.j  a  v a  2 s  .  c  o m
            FileUtils.copyFileToDirectory(aOrigineFile, sDestinationFile.getFile(), preserveAttributes);
        }
    } else {
        if (recursive) {
            FileUtils.copyDirectory(aOrigineFile, sDestinationFile.getFile(), preserveAttributes);
        } else {
            FileUtils.copyDirectory(aOrigineFile, sDestinationFile.getFile(), FileFileFilter.FILE,
                    preserveAttributes);
        }
    }
}

From source file:com.hortonworks.streamline.streams.service.CustomProcessorUploadHandlerTest.java

@Test
public void testFailures() throws IOException {
    final String[] fileNames = { "nocustomprocessorinfo.tar", "nojarfile.tar", "nocustomprocessorimpl.tar" };
    for (String fileName : fileNames) {
        URL url = classLoader.getResource(resourceDirectoryPrefix + fileName);
        String consoleCustomProcessorTarString = url.getFile();
        File consoleCustomProcessorTar = new File(consoleCustomProcessorTarString);
        FileUtils.copyFileToDirectory(consoleCustomProcessorTar, new File(uploadWatchDirectory), false);
        this.customProcessorUploadHandler.created(Paths.get(uploadWatchDirectory).resolve(fileName));
        File f = new File(failedUploadMoveDirectory + File.separator + fileName);
        Assert.assertTrue(f.exists());// w w w. j ava 2 s.c  o m
    }
}

From source file:de.uzk.hki.da.grid.FakeGridFacade.java

/**
 * Scans AIP for marker file to mark this file as corrupted for sing in 
 * acceptance testing on DEV machines/*from   w w  w . j a v  a  2s.co  m*/
 * @author Jens Peters
 * @param custodyFile
 * @return
 */
private boolean checkForCorruptedMarker(File custodyFile) {
    try {

        FileUtils.copyFileToDirectory(custodyFile, new File(tmpFolder), false);
        String packname = custodyFile.getName();
        String dirname = FilenameUtils.getBaseName(custodyFile.getName());

        ArchiveBuilderFactory.getArchiveBuilderForFile(new File("/tmp/" + packname))
                .unarchiveFolder(new File(tmpFolder + packname), new File("/tmp/"));
        logger.debug("Extracting " + packname + " to + " + tmpFolder + dirname);

        IOFileFilter filter = new WildcardFileFilter("DESTROYED*");
        Collection<File> files = FileUtils.listFiles(new File(tmpFolder + dirname), filter,
                DirectoryFileFilter.DIRECTORY);

        if (files.size() > 0) {
            logger.debug("found destroy marker");
            FolderUtils.deleteDirectorySafe(new File(tmpFolder + dirname));
            return true;
        } else
            FolderUtils.deleteDirectorySafe(new File(tmpFolder + dirname));
    } catch (Exception e) {
        logger.error("Error while checking validity on fakedGridfacade on " + custodyFile.getAbsolutePath()
                + ": " + e.getMessage());
    }
    logger.debug("found no destroy marker!");
    return false;
}

From source file:com.hortonworks.streamline.streams.service.CustomProcessorUploadHandlerTest.java

@Test
public void testSuccessfulUpload() throws IOException, ComponentConfigException {
    String fileName = "consolecustomprocessor.tar";
    URL url = classLoader.getResource(resourceDirectoryPrefix + fileName);
    String consoleCustomProcessorTarString = url.getFile();
    File consoleCustomProcessorTar = new File(consoleCustomProcessorTarString);
    FileUtils.copyFileToDirectory(consoleCustomProcessorTar, new File(uploadWatchDirectory), false);
    this.customProcessorUploadHandler.created(Paths.get(uploadWatchDirectory).resolve(fileName));
    new VerificationsInOrder() {
        {//ww  w  .jav a2  s.  com
            InputStream jarFileActual;
            catalogService.addCustomProcessorInfoAsBundle(withEqual(customProcessorInfo),
                    jarFileActual = withCapture());
            times = 1;
            Assert.assertTrue(IOUtils.contentEquals(jarFileActual, jarFile));
        }
    };
}