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

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

Introduction

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

Prototype

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

Source Link

Document

Copies a whole directory to a new location preserving the file dates.

Usage

From source file:com.elastica.browserfactory.OperaCapabilitiesFactory.java

protected String getOperaProfilePath(String path) {
    String realPath = null;//w w w.  jav  a2 s. c  om
    if (path != null && !new File(path).exists()) {
        TestLogging.log("Profile path of Opera Browser:" + path + " not found, use default");
        path = null;
    }

    if (path != null) {

        realPath = path;
    } else {
        try {

            String slash = "\\";
            String profilePath = "C:\\grid\\profile";
            if (!OSUtility.isWindows()) {
                slash = "/";
            }

            profilePath = this.getClass().getResource("/").getFile() + slash + "defaultOperaProfile";
            extractDefaultProfile(profilePath);

            String tempProfilePath = this.getClass().getResource("/").getFile() + slash + new Date().hashCode()
                    + Thread.currentThread().getId();
            FileUtils.copyDirectory(new File(profilePath), new File(tempProfilePath));
            realPath = tempProfilePath + slash + "operaProfile";

        } catch (Exception e) {
            e.printStackTrace();
            realPath = null;
        }
    }

    System.out.println("OperaProfile: " + realPath);
    return realPath;
}

From source file:de.bitinsomnia.webdav.server.MiltonFolderResource.java

@Override
public void copyTo(CollectionResource toCollection, String name)
        throws NotAuthorizedException, BadRequestException, ConflictException {
    LOGGER.debug("Copying folder {} to {}/{}", this.file, toCollection.getName(), name);

    File destinationRootFolder = new File(resourceFactory.getRootFolder(), toCollection.getName());
    File destinationFolder = new File(destinationRootFolder, name);

    try {/*from   w  w w  .  j ava  2  s .c  om*/
        FileUtils.copyDirectory(this.file, destinationFolder);
    } catch (IOException e) {
        LOGGER.error("Error copying folder {}", this.file, e);
        throw new RuntimeIoException(e);
    }
}

From source file:com.linkedin.pinot.core.minion.RawIndexConverter.java

/**
 * NOTE: original segment should be in V1 format.
 * TODO: support V3 format/*  w  ww  .  j av a 2 s . co  m*/
 */
public RawIndexConverter(@Nonnull File originalIndexDir, @Nonnull File convertedIndexDir,
        @Nullable String columnsToConvert) throws Exception {
    FileUtils.copyDirectory(originalIndexDir, convertedIndexDir);
    IndexLoadingConfig indexLoadingConfig = new IndexLoadingConfig();
    indexLoadingConfig.setSegmentVersion(SegmentVersion.v1);
    indexLoadingConfig.setReadMode(ReadMode.mmap);
    _originalIndexSegment = ColumnarSegmentLoader.load(originalIndexDir, indexLoadingConfig);
    _originalSegmentMetadata = (SegmentMetadataImpl) _originalIndexSegment.getSegmentMetadata();
    _convertedIndexDir = convertedIndexDir;
    _convertedProperties = new PropertiesConfiguration(
            new File(_convertedIndexDir, V1Constants.MetadataKeys.METADATA_FILE_NAME));
    _columnsToConvert = columnsToConvert;
}

From source file:com.github.ipaas.ideploy.plugin.core.Comparetor.java

/**
 * ??/*  ww w .j  ava2 s.  c o m*/
 * 
 * @param result
 *             
 * @param pathInfo
 * @return ?
 */
private static String genZipPackage(List<String> result, PathInfo pathInfo) {
    ConsoleHandler.info("??...");
    try {
        String timeStr = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        // ??
        String srcPath = pathInfo.getSrcPath().replaceAll("\\\\", "/");
        // ??
        String savePath = pathInfo.getSavePath().replaceAll("\\\\", "/");
        String tempRootFolder = savePath + "/" + pathInfo.getGroupId() + timeStr;
        String tempCodeFolder = tempRootFolder + "/code";
        FileUtil.newFolder(tempRootFolder);

        StringBuilder updateBuilder = new StringBuilder();
        if (result.size() == 1 && result.get(0).equals("all")) {// ?
            updateBuilder.append("all");
            FileUtils.copyDirectory(new File(srcPath), new File(tempCodeFolder));// ?
            ChineseFileNameFilter.deleteChineseNameFile(savePath, new File(tempRootFolder));// ??
        } else {// ?
            for (String filePath : result) {
                if (filePath == null || filePath.trim().length() <= 1) {
                    continue;
                }
                if (CharUtil.isChinese(filePath)) {
                    ConsoleHandler.error(" ??: " + filePath);
                    continue;// /
                }
                updateBuilder.append(filePath.replaceAll("\\\\", "/")).append("\r\n");
                if (filePath.startsWith("-")) {
                    continue;
                }
                String fileName = filePath.substring(filePath.indexOf("/"), filePath.length());
                File srcFile = new File(new StringBuilder().append(srcPath).append(fileName).toString());
                if (srcFile.exists() && srcFile.isDirectory()) {// 
                    FileUtil.newFolder(tempCodeFolder + fileName);
                } else if (srcFile.exists()) {
                    String folderName = fileName.substring(0, fileName.lastIndexOf("/") + 1);
                    if (folderName != null && folderName.length() > 0) {
                        FileUtil.newFolder(tempCodeFolder + folderName);
                    }
                    File destFile = FileUtil.createFile(tempCodeFolder + fileName);
                    FileUtils.copyFile(srcFile, destFile);
                }
            }
        }

        if (pathInfo.getSourceCodeSvnUrl() != null && !pathInfo.getSourceCodeSvnUrl().equals("")
                && pathInfo.getSourceCodeSvnRevision() != null) {// SVN?
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("sourceCodeSvnRevision", pathInfo.getSourceCodeSvnRevision());
            map.put("sourceCodeSvnUrl", pathInfo.getSourceCodeSvnUrl());
            FileUtil.createTxtFile(tempRootFolder + "/svnInfo.txt", JsonUtil.toJson(map));
        }
        FileUtil.createTxtFile(tempRootFolder + "/update.txt", updateBuilder.toString());
        CompressedFileUtil.compressedFile(tempRootFolder, savePath);
        FileUtil.deleteDirectory(tempRootFolder);// 
        return tempRootFolder + ".zip";
    } catch (Exception e) {
        e.printStackTrace();
        ConsoleHandler.error("?:" + e.getMessage());
    }
    return "";
}

From source file:eu.chocolatejar.eclipse.plugin.cleaner.FunctionalTest.java

/**
 * Create a sample eclipse installation with several bundles in a temporary
 * directory./*from w w w  .  ja va  2  s.co  m*/
 * 
 * @param scenario
 *            name of the folder in test/resources/test-scenarios
 * @throws IOException
 */
public void createEclipseMock(String scenario) throws IOException {
    eclipseMock = Files.createTempDirectory("eclipse-mock-").toFile();
    final File source = FileUtils
            .getFile(FunctionalTest.class.getClassLoader().getResource(scenario).getFile());

    Assume.assumeTrue(eclipseMock.listFiles().length == 0);
    FileUtils.copyDirectory(source, eclipseMock);
    Assume.assumeTrue(eclipseMock.listFiles().length > 0);
}

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

/**
 * @author Gaby Bender//ww w  .j  av  a 2  s .  c o m
 * @throws IOException
 */
private void prepareScan(String virus) throws IOException {

    FileUtils.copyDirectory(Path.makeFile(TEST_CONTRACTOR_WORK_FOLDER, virus, SIP_INPUT + "_"),
            Path.makeFile(TEST_CONTRACTOR_WORK_FOLDER, SIP_INPUT));

    n.setWorkAreaRootPath(WORK_AREA_ROOT_PATH);
    action.setLocalNode(n);
    grid = new FakeGridFacade();
    grid.setGridCacheAreaRootPath("/tmp/");
    action.setGridRoot(grid);
}

From source file:com.github.rinde.gpem17.evo.StatsLogger.java

public void setup(final EvolutionState state, final Parameter base) {
    String seed = state.parameters.getString(new Parameter("seed.0"), null);
    System.out.println("master seed: " + seed);
    checkArgument(seed != null && Ints.tryParse(seed) != null, "seed.0 must be defined");

    String regex = state.parameters.getString(new Parameter("eval").push(Properties.SCENARIOS_REGEX.toString()),
            null);/*from  w  ww. j  a  va2  s. co m*/

    checkArgument(GPEM17.EXPECTED_REGEXES.containsKey(regex), "Unexpected regex: %s, expected one of %s.",
            regex, GPEM17.EXPECTED_REGEXES);

    String name = "-" + GPEM17.EXPECTED_REGEXES.get(regex) + "-s" + seed;

    experimentDirectory = createExperimentDir(new File(RESULTS_MAIN_DIR), name);
    statsLog = new File(experimentDirectory, "best-stats.csv");

    // create best-stats.csv with header
    createHeader(statsLog);

    String fileName = null;
    for (int i = 0; i < state.runtimeArguments.length; i++) {
        if (state.runtimeArguments[i].equals("-file")) {
            fileName = state.runtimeArguments[i + 1];
        }
    }
    System.out.println("Reading properties from: " + fileName);

    File dest = new File(experimentDirectory, "config");

    try {
        dest.mkdirs();
        FileUtils.copyDirectory(new File("files/config"), dest);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    super.setup(state, base);
}

From source file:com.photon.phresco.plugins.DrupalPackage.java

private boolean build() throws MojoExecutionException {
    boolean isBuildSuccess = true;
    try {//from ww  w .ja v  a 2  s  .c  om
        configure();
        FileUtils.copyDirectory(srcDir, targetDir);
        createPackage();
    } catch (Exception e) {
        isBuildSuccess = false;
        getLog().error(e);
    }
    return isBuildSuccess;
}

From source file:com.thruzero.test.support.AbstractCoreTestCase.java

/**
 * Copy the given directory to a temporary directory and return it.
 *//*from w w w . j av  a  2 s . c  o m*/
protected File copyDirToTemp(final String sourceDirName) {
    File result;

    result = getTempTestFile(sourceDirName);
    File sourceDir = null;
    try {
        sourceDir = getTestFile(sourceDirName);
        assertTrue("Source directory named '" + sourceDirName + "' does not exist", sourceDir.exists());
        FileUtils.copyDirectory(sourceDir, result);
    } catch (IOException e) {
        System.out.println("sourceDir:" + sourceDir.getAbsolutePath());
        System.out.println("result:" + result.getAbsolutePath());
        fail("could not copy source directory to temp directory: " + e);
    }

    return result;
}

From source file:lux.solr.TLogTest.java

private void copyDirectory(String srcDir, String destDir) throws IOException {
    FileUtils.copyDirectory(new File(srcDir), new File(destDir));
}