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

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

Introduction

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

Prototype

public static void copyDirectoryToDirectory(File srcDir, File destDir) throws IOException 

Source Link

Document

Copies a directory to within another directory preserving the file dates.

Usage

From source file:com.firewallid.util.FIFile.java

public static void copyFolderToWorkingDirectory(Class clazz, String folderPath, boolean override)
        throws IOException, URISyntaxException {
    File folder = new File(folderPath);
    File workingDirectory = getWorkingDirectory(clazz);
    if (override || !(new File(workingDirectory.getPath() + "/" + folder.getName()).exists())) {
        FileUtils.copyDirectoryToDirectory(folder, workingDirectory);
    }// ww  w  .  ja  v a 2s.com
    LOG.info("Copy folder to working directory: " + folderPath + " -> " + workingDirectory.getPath());
}

From source file:com.gollahalli.manager.FileMover.java

public void forMac(boolean yes) {
    if (yes) {//from   w w  w.j a va2 s  .  com
        try {
            File f = new File("/Applications/JCal.app/Contents/Java");
            if (f.exists() && f.isDirectory()) {
                FileUtils.deleteDirectory(FileUtils.getFile("/Applications/JCal.app/Contents/Java/lib"));
                FileUtils.deleteQuietly(FileUtils.getFile("/Applications/JCal.app/Contents/Java/JCal.jar"));
            }
            FileUtils.copyDirectoryToDirectory(
                    FileUtils.getFile(System.getProperty("user.home") + "/Downloads/JCal/lib"),
                    FileUtils.getFile("/Applications/JCal.app/Contents/Java"));
            FileUtils.copyFileToDirectory(
                    FileUtils.getFile(System.getProperty("user.home") + "/Downloads/JCal/JCal.jar"),
                    FileUtils.getFile("/Applications/JCal.app/Contents/Java"));
        } catch (IOException e) {
        }
    } else {
        try {
            File f = new File("/Applications/JCal.app");
            if (f.exists()) {
                FileUtils.deleteQuietly(FileUtils.getFile("/Applications/JCal.app"));
            }
            FileUtils.moveDirectoryToDirectory(
                    FileUtils.getFile(System.getProperty("user.home") + "/Downloads/JCal.app"),
                    FileUtils.getFile("/Applications/"), false);
        } catch (IOException e) {
        }
    }
}

From source file:com.firewallid.util.FIFile.java

public static void copyFolder(String sourceFolderPath, String destFolderPath, boolean override)
        throws IOException, URISyntaxException {
    File sourceFolder = new File(sourceFolderPath);
    File destFolder = new File(destFolderPath);
    if (override || !(new File(destFolderPath + "/" + sourceFolder.getName()).exists())) {
        FileUtils.copyDirectoryToDirectory(sourceFolder, destFolder);
    }//from   w  ww  . j a  v  a 2s.  c  o  m
    LOG.info("Copy folder: " + sourceFolderPath + " -> " + destFolderPath);
}

From source file:com.thoughtworks.go.helpers.DataUtils.java

public static void cloneCCHome() throws Exception {
    File ccRoot = getConfigXmlAsFile().getParentFile();
    File tmpCCRoot = FileSystemUtils.createDirectory("tmpCCRoot");
    FileUtils.copyDirectoryToDirectory(ccRoot, tmpCCRoot);
}

From source file:net.sf.infrared.tool.util.FileUtil.java

public void copyDirectory(File srcDir, File destDir) {
    try {/* ww  w.  ja va  2 s .  c  o  m*/
        FileUtils.copyDirectoryToDirectory(srcDir, destDir);
    } catch (IOException ex) {
        throw new InfraredToolException("Failed to copy directory " + srcDir.getAbsolutePath()
                + " to directory " + destDir.getAbsolutePath(), ex);
    }
}

From source file:ch.bender.evacuate.RunnerCheckDirectoriesTest.java

/**
 * Executed at loading of this class (static inizalizer).
 * <p>/*  ww w.j  ava2s  .  c  om*/
 * @throws Throwable
 *         On any problem
 */
@BeforeClass
public static final void doBeforeClass() throws Throwable {
    System.out.println("doBeforeClass() entering...");

    try {
        if (Files.exists(Testconstants.ROOT_DIR)) {
            Helper.deleteDirRecursive(Testconstants.ROOT_DIR);
        }

        Files.createDirectory(Testconstants.ROOT_DIR);

        Path orig = Testconstants.createNewFolder(Testconstants.ROOT_DIR, "orig");
        Path origSub1 = Testconstants.createNewFolder(orig, "sub1");
        Path origSub2 = Testconstants.createNewFolder(orig, "sub2");

        Path file1 = Testconstants.createNewFile(orig, "file1.txt");
        Path fileSub1 = Testconstants.createNewFile(origSub1, "fileSub1.txt");
        Path fileSub2 = Testconstants.createNewFile(origSub2, "fileSub2.txt");

        Path backup = Testconstants.createNewFolder(Testconstants.ROOT_DIR, "backup");
        FileUtils.copyDirectoryToDirectory(origSub1.toFile(), backup.toFile());
        FileUtils.copyDirectoryToDirectory(origSub2.toFile(), backup.toFile());
    } catch (Throwable e) {
        System.err.println("Throwable caught in doBeforeClass()");
        e.printStackTrace();
        throw e;
    }

    System.out.println("doBeforeClass() leaving...");
}

From source file:com.predic8.membrane.examples.tests.CustomInterceptorTest.java

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("custom-interceptor");

    BufferLogger b = new BufferLogger();
    Process2 ant = new Process2.Builder().in(baseDir).executable("ant compile").withWatcher(b).start();
    try {// w ww. ja v a2  s.c  om
        int exitCode = ant.waitFor(60000);
        if (exitCode != 0)
            throw new RuntimeException("Ant exited with code " + exitCode + ": " + b.toString());
    } finally {
        ant.killScript();
    }

    FileUtils.copyDirectoryToDirectory(new File(baseDir, "build/classes"), getMembraneHome());

    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        SubstringWaitableConsoleEvent invoked = new SubstringWaitableConsoleEvent(sl, "MyInterceptor invoked");
        getAndAssert200("http://localhost:2000/");
        assertTrue(invoked.occurred());
    } finally {
        sl.killScript();
    }
}

From source file:com.streamsets.pipeline.stage.destination.solr.TestSolrTarget.java

@BeforeClass
public static void beforeTest() throws Exception {
    File solrHomeDir = new File("target", UUID.randomUUID().toString());
    Assert.assertTrue(solrHomeDir.mkdirs());
    URL url = Thread.currentThread().getContextClassLoader().getResource("solr/");
    Assert.assertNotNull(url);//w w  w .j  a  v  a 2  s  .co m
    FileUtils.copyDirectoryToDirectory(new File(url.toURI()), solrHomeDir);
    createJetty(solrHomeDir.getAbsolutePath() + "/solr", null, null);
}

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

/**
 * Copies a file or directory/*w ww  . j a  va2s . c om*/
 * @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.photon.phresco.util.FileUtil.java

public static boolean moveUploadedThemeBundle(File extractedFile, ApplicationInfo appInfo)
        throws PhrescoException {
    boolean flag = true;
    StringBuilder bundlePath = new StringBuilder(Utility.getProjectHome());
    try {//from ww  w .ja  v  a2 s .c  om
        String destFolder = getThemeBundleUploadDir(appInfo);
        bundlePath.append(appInfo.getAppDirName()).append(File.separator).append(destFolder);
        File destination = new File(bundlePath.toString());

        if (StringUtils.isEmpty(destFolder) || !destination.exists()) {
            flag = false;
        } else if (destination.exists()) {
            FileUtils.copyDirectoryToDirectory(extractedFile, destination);
        }
    } catch (Exception e) {
        flag = false;
        throw new PhrescoException(e);
    }

    return flag;
}