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.sitewhere.configuration.FileSystemTenantConfigurationResolver.java

@Override
public byte[] createDefaultTenantConfiguration() throws SiteWhereException {
    File root = new File(getGlobalConfigurationResolver().getConfigurationRoot());
    if (!root.exists()) {
        throw new SiteWhereException("Global configuration root not found.");
    }/*from w ww.j  a v a2  s  . co m*/
    File tenants = new File(root, FileSystemTenantConfigurationResolver.TENANTS_FOLDER);
    if (!tenants.exists()) {
        throw new SiteWhereException("Unable to create tenant resources folder.");
    }
    File tenantFolder = new File(tenants, tenant.getId());
    File templateFolder = new File(root, FileSystemTenantConfigurationResolver.DEFAULT_TENANT_TEMPLATE_FOLDER);
    if (!templateFolder.exists()) {
        throw new SiteWhereException("Tenant template folder not found.");
    }
    try {
        FileUtils.copyDirectory(templateFolder, tenantFolder);
    } catch (IOException e) {
        throw new SiteWhereException("Unable to copy template folder for tenant.");
    }

    LOGGER.info("Copying new tenant from template at " + templateFolder.getAbsolutePath() + ".");
    File activeTenantFile = getTenantConfigurationFile(TENANT_SUFFIX_ACTIVE);
    return FileSystemGlobalConfigurationResolver.getFileQuietly(activeTenantFile);
}

From source file:com.jayway.maven.plugins.android.phase04processclasses.DexMojo.java

private File unpackClasses(File inputFile) throws MojoExecutionException {
    File outputDirectory = new File(project.getBuild().getDirectory(), "android-classes");
    for (Artifact artifact : getRelevantCompileArtifacts()) {

        if (artifact.getFile().isDirectory()) {
            try {
                FileUtils.copyDirectory(artifact.getFile(), outputDirectory);
            } catch (IOException e) {
                throw new MojoExecutionException("IOException while copying "
                        + artifact.getFile().getAbsolutePath() + " into " + outputDirectory.getAbsolutePath(),
                        e);/*from  w  ww .j av a2  s. c  o  m*/
            }
        } else {
            try {
                unjar(new JarFile(artifact.getFile()), outputDirectory);
            } catch (IOException e) {
                throw new MojoExecutionException("IOException while unjarring "
                        + artifact.getFile().getAbsolutePath() + " into " + outputDirectory.getAbsolutePath(),
                        e);
            }
        }

    }

    try {
        unjar(new JarFile(inputFile), outputDirectory);
    } catch (IOException e) {
        throw new MojoExecutionException("IOException while unjarring " + inputFile.getAbsolutePath() + " into "
                + outputDirectory.getAbsolutePath(), e);
    }
    return outputDirectory;
}

From source file:com.enonic.cms.core.resource.FileResourceServiceImpl.java

private boolean doCopyResourceFolder(final FileResourceName to, final File fromFile) {
    File toFile = getFile(to);/*from  ww w  .  j  a  v  a 2 s  .  co  m*/

    try {
        FileUtils.copyDirectory(fromFile, toFile);
        return true;
    } catch (IOException e) {
        throw new RuntimeException("Not able to copy directory " + fromFile + " to " + toFile, e);
    }
}

From source file:com.linkedin.pinot.tools.segment.converter.DictionaryToRawIndexConverter.java

/**
 * This method converts the specified columns of the given segment from dictionary encoded
 * forward index to raw index without dictionary.
 *
 * @param segmentDir Segment directory//w w  w  . j a  va  2 s. com
 * @param columns Columns to convert
 * @param outputDir Directory for writing output segment
 * @param compressOutput Tar/gzip the output segment
 * @return True if successful, False otherwise
 * @throws Exception
 */
public boolean convertSegment(File segmentDir, String[] columns, File outputDir, boolean compressOutput)
        throws Exception {
    File newSegment;

    if (segmentDir.isFile()) {
        if (segmentDir.getName().endsWith(".tar.gz") || segmentDir.getName().endsWith(".tgz")) {
            LOGGER.info("Uncompressing input segment '{}'", segmentDir);
            newSegment = TarGzCompressionUtils.unTar(segmentDir, outputDir).get(0);
        } else {
            LOGGER.warn("Skipping non-segment file '{}'", segmentDir.getAbsoluteFile());
            return false;
        }
    } else {
        newSegment = new File(outputDir, segmentDir.getName());
        newSegment.mkdir();
        FileUtils.copyDirectory(segmentDir, newSegment);
    }

    IndexSegment segment = Loaders.IndexSegment.load(newSegment, ReadMode.mmap);
    for (String column : columns) {
        LOGGER.info("Converting column '{}' for segment '{}'.", column, segment.getSegmentName());
        convertOneColumn(segment, column, newSegment);
    }

    updateMetadata(newSegment, columns, _tableName);
    segment.destroy();

    if (compressOutput) {
        LOGGER.info("Compressing segment '{}'", newSegment);
        TarGzCompressionUtils.createTarGzOfDirectory(newSegment.getAbsolutePath(),
                newSegment.getAbsolutePath());
        FileUtils.deleteQuietly(newSegment);
    }
    return true;
}

From source file:at.kc.tugraz.ss.cloud.impl.fct.op.SSCloudPublishServiceFct.java

License:asdf

private static void copyFilesLocally(final String localWorkTmpDirPath, final String serviceDestDirPath)
        throws Exception {

    try {/*from   ww  w  . j  a  v  a 2  s .  co m*/
        FileUtils.copyFile(new File(localWorkTmpDirPath + SSVocConf.fileNameSSSConf),
                new File(serviceDestDirPath + SSVocConf.fileNameSSSConf));

        FileUtils.copyFile(new File(SSFileU.dirWorking() + SSVocConf.fileNameSSSJar),
                new File(serviceDestDirPath + SSVocConf.fileNameSSSJar));

        FileUtils.copyFile(new File(SSFileU.dirWorking() + SSVocConf.fileNameLog4JProperties),
                new File(serviceDestDirPath + SSVocConf.fileNameLog4JProperties));

        FileUtils.copyFile(new File(SSFileU.dirWorking() + SSVocConf.fileNameRunitBat),
                new File(serviceDestDirPath + SSVocConf.fileNameRunitBat));

        FileUtils.copyDirectory(new File(SSFileU.dirWorking() + SSVocConf.dirNameLib),
                new File(serviceDestDirPath + SSVocConf.dirNameLib));

    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    } finally {
        FileUtils.deleteDirectory(new File(localWorkTmpDirPath));
    }
}

From source file:ml.shifu.shifu.core.processor.ComboModelProcessor.java

/**
 * Create folder for sub-models, and create related files for sub-models.
 * All settings in sub-model can have their own settings - including stats/norm/varsel/train
 *
 * @return 0 successful, otherwise failed
 * @throws IOException any io exception//from   www.j  a  v  a  2 s . c  o  m
 */
private int initComboModels() throws IOException {
    if (this.comboModelTrain == null) {
        LOG.error("ComboModelTrain doesn't exists.");
        return 1;
    }

    // 0. create "EvalTrain" evaluation set in parent ModelConfig.json
    EvalConfig evalTrain = modelConfig.getEvalConfigByName(TRAIN_EVAL_NAME);
    if (evalTrain == null) { // create if not exists, if user run multi times, the "EvalTrain" may already exists
        evalTrain = new EvalConfig();
        evalTrain.setName(TRAIN_EVAL_NAME);
        evalTrain.setDataSet(modelConfig.getDataSet().cloneRawSourceData());
        modelConfig.getEvals().add(evalTrain);
    }

    // 1. create all sub-model folders and do the setting for each of them
    String[] subModelNames = new String[this.comboModelTrain.getSubTrainConfList().size() - 1];
    for (int i = 0; i < this.comboModelTrain.getSubTrainConfList().size() - 1; i++) {
        SubTrainConf subTrainConf = this.comboModelTrain.getSubTrainConfList().get(i);
        String subModelName = subTrainConf.getModelName();

        // 1.0) save all sub model names, it will used as variables for assemble model
        subModelNames[i] = subModelName;

        // 1.1) create folder for sub-model
        new File(subModelName).mkdirs();

        // 1.2) create ModelConfig
        ModelConfig subModelConfig = this.modelConfig.clone();
        if (StringUtils.isNotBlank(subTrainConf.getDataFilterExpr())) {
            subModelConfig.getDataSet().setFilterExpressions(subTrainConf.getDataFilterExpr());
        }
        subModelConfig.getBasic().setName(subModelName);
        subModelConfig.setStats(subTrainConf.getModelStatsConf());
        subModelConfig.setNormalize(subTrainConf.getModelNormalizeConf());
        subModelConfig.setVarSelect(subTrainConf.getModelVarSelectConf());
        subModelConfig.setTrain(subTrainConf.getModelTrainConf());

        // 1.3) copy all evaluation set except "EvalTrain"
        List<EvalConfig> subEvalConfigs = new ArrayList<EvalConfig>();
        for (EvalConfig eval : modelConfig.getEvals()) {
            if (!eval.getName().equalsIgnoreCase(TRAIN_EVAL_NAME)) {
                EvalConfig subEval = eval.clone();
                subEval.setPerformanceScoreSelector(SCORE_MEAN_FIELD);
                subEvalConfigs.add(subEval);
            }
        }
        subModelConfig.setEvals(subEvalConfigs);

        // 1.4) copy columns/ folder and save to sub-model's ModelConfig.json
        FileUtils.copyDirectory(new File(Constants.COLUMN_META_FOLDER_NAME),
                new File(subModelName, Constants.COLUMN_META_FOLDER_NAME));
        saveModelConfig(subModelName, subModelConfig);
    }

    // 2. create assemble model folder and do setting for it
    //  2.0) clone from parent model config to generate assemble model config
    ModelConfig assembleModelConfig = this.modelConfig.clone();
    String assembleModelName = this.comboModelTrain.getAssembleTrainConf().getModelName();
    new File(assembleModelName).mkdirs();
    assembleModelConfig.setModelSetName(assembleModelName);

    //  2.1) set the training data source to "EvalTrain" score of parent model
    if (SourceType.HDFS.equals(evalTrain.getDataSet().getSource())) {
        assembleModelConfig.getDataSet().setDataPath(pathFinder.getEvalScorePath(evalTrain));
        assembleModelConfig.getDataSet().setHeaderPath(pathFinder.getEvalScoreHeaderPath(evalTrain));
    } else if (SourceType.LOCAL.equals(evalTrain.getDataSet().getSource())) {
        File evalScoreFile = new File(pathFinder.getEvalScorePath(evalTrain));
        assembleModelConfig.getDataSet().setDataPath(evalScoreFile.getAbsolutePath());
        assembleModelConfig.getDataSet().setHeaderPath("");
    }
    assembleModelConfig.getDataSet().setDataDelimiter("|");
    assembleModelConfig.getDataSet().setHeaderDelimiter("|");
    assembleModelConfig.getDataSet().setCategoricalColumnNameFile(null);
    FileUtils.copyDirectory(new File(Constants.COLUMN_META_FOLDER_NAME),
            new File(assembleModelName, Constants.COLUMN_META_FOLDER_NAME));

    //  2.2) create force selects file
    assembleModelConfig.getVarSelect().setForceSelectColumnNameFile(null);
    assembleModelConfig.getVarSelect().setForceRemoveColumnNameFile(null);
    assembleModelConfig.getVarSelect().setForceEnable(true);
    assembleModelConfig.getVarSelect().setFilterNum(subModelNames.length);
    assembleModelConfig.getVarSelect().setFilterEnable(true);

    //  2.3) set the evaluation data source to the eval's output of parent model
    List<EvalConfig> assembleEvalConfigs = new ArrayList<EvalConfig>();
    for (EvalConfig eval : modelConfig.getEvals()) {
        if (!eval.getName().equalsIgnoreCase(TRAIN_EVAL_NAME)) {
            EvalConfig assembleEval = eval.clone();
            if (SourceType.HDFS.equals(eval.getDataSet().getSource())) {
                assembleEval.getDataSet().setDataPath(pathFinder.getEvalScorePath(eval));
                assembleEval.getDataSet().setHeaderPath(pathFinder.getEvalScoreHeaderPath(eval));
            } else if (SourceType.LOCAL.equals(eval.getDataSet().getSource())) {
                File evalScoreFile = new File(pathFinder.getEvalScorePath(eval));
                assembleEval.getDataSet().setDataPath(evalScoreFile.getAbsolutePath());
                assembleEval.getDataSet().setHeaderPath("");
            }

            assembleEval.getDataSet().setDataDelimiter("|");
            assembleEval.getDataSet().setHeaderDelimiter("|");
            assembleEval.setPerformanceScoreSelector(SCORE_MEAN_FIELD);
            assembleEvalConfigs.add(assembleEval);
        }

        eval.setPerformanceScoreSelector(formatPigNS(subModelNames[0]) + "::" + SCORE_MEAN_FIELD);
    }
    assembleModelConfig.setEvals(assembleEvalConfigs);

    //  2.4) save assemble ModelConfig.json
    saveModelConfig(assembleModelName, assembleModelConfig);

    // 3. save parent model config
    saveModelConfig();

    return 0;
}

From source file:dsfixgui.FileIO.DSFixFileController.java

public void installDSFix() {

    ui.printConsole(INSTALLING_DSF);//from   www  .  jav  a2  s  .  c om
    File srcFile = null;
    File destFile = null;
    boolean copyError = false;

    for (int i = 0; i < DSF_FILES.length; i++) {
        String file = DSF_FILES[i];
        srcFile = new File(FILES_DIR + DSF_FOLDER + "\\" + file);
        destFile = new File(ui.getDataFolder().getPath() + "\\" + file);

        try {
            if (i != DSF_FILES.length - 2) {
                FileUtils.copyFile(srcFile, destFile);
            } else {
                FileUtils.copyDirectory(srcFile, destFile);
            }
            ui.printConsole(COPYING + file);
        } catch (IOException iOE) {
            ui.printConsole(FAILED_FILE_COPY_ERR + file);
            copyError = true;
        }
    }

    if (!copyError) {
        ui.checkForDSFix();
        if (ui.getDSPWStatus() != 0) {
            installFPSFix();
        }
        turnOffIngameAA();
        ui.printConsole(DSF_INSTALLED_SUCCESS);
    } else {
        ui.printConsole(DSF_INSTALLED_ERRORS);
        ContinueDialog cD = new ContinueDialog(300.0, 80.0, DIALOG_TITLE_INSTALL_ERR, DIALOG_MSG_FILE_COPY_ERR,
                DIALOG_BUTTON_TEXTS[2], DIALOG_BUTTON_TEXTS[3]);
        if (cD.show()) {
            uninstallDSFix();
        }

        ui.checkForDSFix();
    }

}

From source file:eu.asterics.ape.packaging.Packager.java

/**
 * Copies all the custom files of the folder APE.projectDir/bin to APE.buildDir/merged/bin
 * @param buildDir/*from w ww . j av a2 s  . c  om*/
 */
public void copyCustomFiles(File buildDir) {
    File customBinDir = ResourceRegistry.resolveRelativeFilePath(projectDir, CUSTOM_BIN_FOLDER);
    File buildMergedBinDir = ResourceRegistry.resolveRelativeFilePath(buildMergedDir, BIN_FOLDER);
    try {
        Notifier.info("Copying custom files from <" + customBinDir + "> to <" + buildMergedBinDir + ">");
        FileUtils.copyDirectory(customBinDir, buildMergedBinDir);
    } catch (IOException e) {
        Notifier.warning(
                "Could not copy custom files of <" + customBinDir + ">, to <" + buildMergedBinDir + ">", e);
    }
}

From source file:com.sap.prd.mobile.ios.mios.XCodeContextTest.java

@Test
public void testIsImmutable() throws Exception {
    Map<String, String> userOptions = new HashMap<String, String>();
    Map<String, String> managedOptions = new HashMap<String, String>();
    managedOptions.put(Options.ManagedOption.CONFIGURATION.getOptionName(), "Release");
    managedOptions.put(Options.ManagedOption.SDK.getOptionName(), "mysdk");
    managedOptions.put(Options.ManagedOption.PROJECT.getOptionName(), "MyLibrary.xcodeproj");
    Options options = new Options(userOptions, managedOptions);

    HashMap<String, String> userSettings = new HashMap<String, String>();
    HashMap<String, String> managedSettings = new HashMap<String, String>();
    managedSettings.put(Settings.ManagedSetting.CODE_SIGN_IDENTITY.name(), "");
    Settings settings = new Settings(userSettings, managedSettings);

    List<String> buildActions = new ArrayList<String>(Arrays.asList("clean", "build"));

    File _projectDir = new File(projectDirectory.getParentFile().getCanonicalFile(), "MyLib2");
    _projectDir.deleteOnExit();/*  ww w.  j a  v  a2 s.c  o m*/

    FileUtils.copyDirectory(projectDirectory, _projectDir);

    final XCodeContext xCodeContext = new XCodeContext(buildActions, _projectDir, System.out, settings,
            options);

    int hashCode = xCodeContext.hashCode();

    managedOptions.put("managedOptionAddedAfterwards", "xxxx");
    managedSettings.put("managedSettigAddedAfterwards", "yyyy");

    userOptions.put("userOptionAddedAfterwards", "1111");
    userSettings.put("userSettigAddedAfterwards", "2222");

    buildActions.add("addedAfterwards");

    _projectDir.renameTo(new File(projectDirectory.getParent(), "MyLib3"));

    assertEquals("Context is not immutable.", hashCode, xCodeContext.hashCode());
}

From source file:com.collective.celos.CelosClientServerTest.java

@Test
public void testGetWorkflowStatusNoInfo() throws Exception {

    File src = new File(Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/client/wf-list").toURI());
    FileUtils.copyDirectory(src, workflowsDir);

    celosClient.iterateScheduler();//from   w w  w  . j a v a  2s. co  m
    WorkflowStatus status = celosClient.getWorkflowStatus(new WorkflowID("workflow-1"));
    Assert.assertNull(status.getInfo().getUrl());
    Assert.assertTrue(status.getInfo().getContacts().isEmpty());
}