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) throws IOException 

Source Link

Document

Copies a file to a directory preserving the file date.

Usage

From source file:com.garethahealy.camel.file.loadbalancer.example1.routes.HandlesOneFileMultipleReadersTest.java

@Override
protected void doPreSetup() throws Exception {
    File directory = FileUtils.toFile(new URL("file:" + rootDirectory));
    FileUtils.deleteDirectory(directory);

    directory.mkdir();// w ww. ja  va 2s  .  c o  m

    URL file1 = HandlesOneFileMultipleReadersTest.class.getClassLoader()
            .getResource("example-files/afile1.log");

    Assert.assertNotNull(file1);

    FileUtils.copyFileToDirectory(FileUtils.toFile(file1), directory);

    LOG.info("Moved files to: " + directory.getAbsolutePath());
}

From source file:io.github.bunnyblue.droidfix.classcomputer.ClassComputer.java

public static void copyDiffClasses(ArrayList<ClassObject> diffClasses, String rootPath) {

    for (ClassObject classObject : diffClasses) {
        classObject.getClassName().replaceAll(".", "/");

        String subPath = classObject.getClassName().replaceAll("\\.", "/");
        if (subPath.lastIndexOf("/") != -1) {
            subPath = subPath.substring(0, subPath.lastIndexOf("/"));
            subPath = rootPath + "/" + subPath;
            subPath = subPath.replaceAll("\\\\", "/");
            File subDir = new File(subPath);
            subDir.mkdirs();//  w ww .  j  a  v  a  2  s.  c om
            File localClass = new File(classObject.getLocalPath());
            try {
                FileUtils.copyFileToDirectory(localClass, subDir);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.err.println("Copy diff class " + localClass.getAbsolutePath());

        }

    }
}

From source file:com.orange.mmp.dao.flf.MidletDaoFlfImpl.java

public Midlet createOrUdpdate(Midlet midlet) throws MMPDaoException {
    if (midlet == null || midlet.getJadLocation() == null || midlet.getJarLocation() == null
            || midlet.getType() == null) {
        throw new MMPDaoException("missing or bad data access object");
    }// w  ww.j  ava  2s  .c  o  m

    try {
        this.lock.lock();
        File typeFolder = new File(this.path, midlet.getType());
        if (!typeFolder.isDirectory())
            FileUtils.forceMkdir(typeFolder);
        File jadFile = new File(new URI(midlet.getJadLocation()));
        FileUtils.copyFileToDirectory(jadFile, typeFolder);
        File jarFile = new File(new URI(midlet.getJarLocation()));
        FileUtils.copyFileToDirectory(jarFile, typeFolder);
        FileUtils.touch(new File(this.path));
    } catch (IOException ioe) {
        throw new MMPDaoException("failed to add PFM : " + ioe.getMessage());
    } catch (URISyntaxException use) {
        throw new MMPDaoException("failed to add PFM : " + use.getMessage());
    } finally {
        this.lock.unlock();
    }

    return midlet;
}

From source file:com.ColonelHedgehog.Sites.Services.URLServices.DLC.java

public static void parseCrossNetworkParseable(final File f) {
    new BukkitRunnable() {

        @Override/*from ww w. j av  a 2s  .com*/
        public void run() {

            try {
                BufferedReader br = null;
                try {
                    br = new BufferedReader(new FileReader(f));
                    int linenum = 1;
                    String read;

                    while ((read = br.readLine()) != null) {
                        //System.out.println("[CS | CNP] Reading... " + linenum + ". Parsing... " + reading);
                        if (read.startsWith("~ (action#copyfiles) ")) {
                            System.out.println(
                                    "[CS | CNP] Found action#copyfiles at line " + linenum + ". Parsing...");
                            String[] sy = read.split(" : ");
                            File source = new File(sy[0].replace("~ (action#copyfiles) ", "")
                                    .replace("#pluginsfolder#", plugin.getDataFolder().getParent()));
                            File dest = new File(
                                    sy[1].replace("#pluginsfolder#", plugin.getDataFolder().getParent()));

                            System.out.println("[CS | CNP] Copying source: " + source.toString());
                            System.out.println("[CS | CNP] Copying to destination: " + dest.toString());
                            int schematicscount = 0;

                            File[] files = source.listFiles();

                            if (files == null) {
                                System.out.println(
                                        "[CS | CNP] ERROR: No files in directory: " + source.getPath());
                                return;
                            }
                            for (File schematic : files) {
                                FileUtils.copyFileToDirectory(schematic, dest);
                                schematicscount++;
                            }

                            System.out.println("[CS | CNP] Copied files. Total copied: " + schematicscount);
                        } else if (read.startsWith("~ (action#writetoconfig) ")) {
                            //System.out.println("[CS | CNP] Found action#writetoconfig at line " + linenum + ". Parsing...");
                            //String[] sy = read.split(" : ");

                            //File source = new File(sy[0].replace("~ (action#writetoconfig) ", "").replace("#pluginsfolder#", plugin.getDataFolder().getParent()));
                            //parseCrossNetworkParseableScript(source);
                            /* ===== Not nescessary right now! ===== */
                        }
                        linenum++;
                    }
                } catch (IOException ex) {
                    Logger.getLogger(DLC.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    try {
                        if (br != null) {
                            br.close();
                        } else {
                            System.out.println("[CS | CNP] Failed to close buffered reader!");
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(DLC.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                System.out.println("[CS | CNP] Finished parsing. Deleting package...");
                FileUtils.deleteDirectory(f.getParentFile());
            } catch (IOException ex) {
                Logger.getLogger(DLC.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }.runTaskAsynchronously(plugin);
}

From source file:net.orpiske.sdm.lib.io.IOUtil.java

/**
 * Copies a file or directory//from   w w  w.j a  va  2s  .  co  m
 * @param from the source file or directory
 * @param to the destination file or directory
 * @param overwrite whether or not to overwrite the destination file/directory
 * @throws IOException if the source is not found or there are access restrictions 
 */
public static void copy(final String from, final String to, boolean overwrite) throws IOException {
    File fromFile = new File(from);
    File toFile = new File(to);

    if (!fromFile.exists()) {
        throw new IOException("File or directory not found: " + from);
    }

    if (fromFile.isDirectory()) {

        if (toFile.exists() && !toFile.isDirectory()) {
            throw new IOException("Illegal copy: trying to copy a directory into a file");
        } else {
            FileUtils.copyDirectoryToDirectory(fromFile, toFile);
        }
    } else {
        if (toFile.isDirectory()) {
            FileUtils.copyFileToDirectory(fromFile, toFile);
        } else {
            if (toFile.exists()) {
                if (!overwrite) {
                    System.out.println(
                            "Ignoring copy from " + from + " to " + to + " because overwrite flag is not set");
                    return;
                }
            }

            FileUtils.copyFile(fromFile, toFile);
        }
    }

}

From source file:com.garethahealy.camel.file.loadbalancer.example1.routes.ReadThreeFilesWithThreeReadersTest.java

@Override
protected void doPreSetup() throws Exception {
    File directory = FileUtils.toFile(new URL("file:" + rootDirectory));
    FileUtils.deleteDirectory(directory);

    directory.mkdir();/*from  ww  w .ja va  2  s.c o m*/

    URL file1 = ReadThreeFilesWithThreeReadersTest.class.getClassLoader()
            .getResource("example-files/afile1.log");
    URL file2 = ReadThreeFilesWithThreeReadersTest.class.getClassLoader()
            .getResource("example-files/bfile2.log");
    URL file3 = ReadThreeFilesWithThreeReadersTest.class.getClassLoader()
            .getResource("example-files/cfile3.log");

    Assert.assertNotNull(file1);
    Assert.assertNotNull(file2);
    Assert.assertNotNull(file3);

    FileUtils.copyFileToDirectory(FileUtils.toFile(file1), directory);
    FileUtils.copyFileToDirectory(FileUtils.toFile(file2), directory);
    FileUtils.copyFileToDirectory(FileUtils.toFile(file3), directory);

    LOG.info("Moved files to: " + directory.getAbsolutePath());
}

From source file:com.withbytes.tentaculo.traverser.windows.WindowsTraverser.java

public boolean backup(String sourcePath, IPathTranslator translator, String backupPath)
        throws TentaculoException {
    File source = new File(translator.translatePath(sourcePath));
    File destination = new File(backupPath);
    try {/* www  .jav a 2s. c om*/
        if (!source.exists()) {
            return false;
        }
        if (source.isFile()) {
            FileUtils.copyFileToDirectory(source, destination);
        }
        if (source.isDirectory()) {
            FileUtils.copyDirectoryToDirectory(source, destination);
        }
    } catch (IOException ex) {
        return false;
    }
    return true;
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

@Before
public void initManagedSchemaCore() throws Exception {
    File tmpSolrHome = createTempDir();
    File tmpConfDir = new File(tmpSolrHome, confDir);
    File testHomeConfDir = new File(SOLR_HOME, confDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, SOLRCONFIG_XML), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, SCHEMA_XML), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, QNAMES_TXT), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, DATATYPES_XML), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, STOPWORDS_TXT), tmpConfDir);

    // initCore will trigger an upgrade to managed schema, since the solrconfig*.xml has
    // <schemaFactory class="ManagedIndexSchemaFactory" ... />
    initCore(SOLRCONFIG_XML, SCHEMA_XML, tmpSolrHome.getPath());
}

From source file:net.sourceforge.atunes.kernel.executors.ImportProcess.java

public void run() {
    super.run();//w  w  w. ja  v a2 s. co  m
    File destination = new File(HandlerProxy.getRepositoryHandler().getRepositoryPath());
    int filesImported = 0;

    HandlerProxy.getVisualHandler().getCopyProgressDialog().getProgressLabel()
            .setText(Integer.toString(filesImported));
    boolean errors = false;
    logger.info("Copying songs from device to repository");
    try {
        for (Iterator it = songs.iterator(); it.hasNext() && !interrupt;) {
            AudioFile song = (AudioFile) it.next();
            File destDir = getDirectory(song, destination, structure);
            FileUtils.copyFileToDirectory(song, destDir);
            if (filePattern != null) {
                File destFile = new File(
                        destDir.getAbsolutePath() + SystemProperties.fileSeparator + song.getName());
                String newName = getNewName(filePattern, song);
                destFile.renameTo(
                        new File(destDir.getAbsolutePath() + SystemProperties.fileSeparator + newName));
            }
            filesImported++;
            HandlerProxy.getVisualHandler().getCopyProgressDialog().getProgressLabel()
                    .setText(Integer.toString(filesImported));
            HandlerProxy.getVisualHandler().getCopyProgressDialog().getProgressBar().setValue(filesImported);
        }
    } catch (IOException e) {
        errors = true;
        logger.error(e.getMessage());
        logger.debug(e);
    }
    logger.info("Copying process done");
    CopyProgressDialog dialog = HandlerProxy.getVisualHandler().getCopyProgressDialog();
    dialog.setVisible(false);
    if (errors)
        HandlerProxy.getVisualHandler().showErrorDialog(LanguageTool.getString("ERRORS_IN_COPYING_PROCESS"));

}

From source file:com.sonar.it.jenkins.orchestrator.container.JenkinsDownloader.java

public synchronized File download(JenkinsDistribution distrib) {
    LOG.info("Downloading Jenkins-" + distrib.getVersion());

    // Add a "j" prefix to not conflict with SonarQube
    File toDir = new File(fileSystem.workspace(), "j" + String.valueOf(sharedDirId.addAndGet(1)));
    if (toDir.exists()) {
        try {/*www  .  j ava 2  s.c o m*/
            FileUtils.cleanDirectory(toDir);
        } catch (IOException e) {
            throw new IllegalStateException("Fail to clean directory: " + toDir, e);
        }
    }

    LOG.info("Download Jenkins-" + distrib.getVersion() + " in " + toDir.getAbsolutePath());
    File war = downloadWar(distrib);

    LOG.info("Copy " + war);
    try {
        FileUtils.copyFileToDirectory(war, toDir);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return toDir;
}