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

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

Introduction

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

Prototype

public static void cleanDirectory(File directory) throws IOException 

Source Link

Document

Cleans a directory without deleting it.

Usage

From source file:com.github.ipaas.ideploy.agent.util.SVNUtil.java

public static void getDeta4UpdateAll(final String path, final long revision, String localPath)
        throws Exception {

    DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
    ISVNAuthenticationManager authManager = SVNWCUtil
            .createDefaultAuthenticationManager(Constants.CRS_REPOS_USER, Constants.CRS_REPOS_PWD);
    SVNClientManager svnClientManager = null;

    try {//from   w  w  w  . j  a  va  2  s. c  om
        //
        File localDict = new File(localPath);
        if (!localDict.exists()) {
            localDict.mkdirs();
        } else {
            FileUtils.cleanDirectory(localDict);
        }

        svnClientManager = SVNClientManager.newInstance(options, authManager);

        Collection<SVNLog> logs = new LinkedList<SVNLog>();
        logs.add(new SVNLog4All());

        //
        export(svnClientManager, path, revision, localPath + Constants.UPDPKG_CODEDIR);

        //
        writeLogToFile(logs, new File(localPath + Constants.UPDPKG_UPDTXT));
    } finally {
        if (svnClientManager != null) {
            svnClientManager.dispose();
        }
    }
}

From source file:com.netflix.imfutility.itunes.ITunesFormatBuilder.java

private void createItmspDir() throws IOException {
    DynamicTemplateParameterContext dynamicContext = contextProvider.getDynamicContext();
    String itmspName = dynamicContext.getParameterValueAsString(DYNAMIC_PARAM_OUTPUT_ITMSP);

    logger.info("Creating {} output directory...", itmspName);

    itmspDir = new File(contextProvider.getWorkingDir(), itmspName);
    logger.info("Itmsp output directory: {}", itmspDir);
    if (Files.exists(itmspDir.toPath())) {
        FileUtils.cleanDirectory(itmspDir);
    } else {/*w ww  . j  a v  a  2  s .co  m*/
        if (!itmspDir.mkdir()) {
            throw new ConversionException(String.format("Couldn't create %s output directory!", itmspName));
        }
    }

    logger.info("Created {} output directory: OK\n", itmspName);
}

From source file:com.servicelibre.jxsl.scenario.test.xspec.XspecTestScenarioRunner.java

public void cleanOutputDir() {
    try {
        FileUtils.cleanDirectory(outputDir);
    } catch (IOException e) {
        logger.equals(e);
    }

}

From source file:it.infn.ct.ToscaIDCInterface.java

/**
 *  Generate the output directory.//w  ww .  j  ava2  s  . c  om
 */
public final void mkOutputDir() {
    String outputSandbox = toscaCommand.getActionInfo() + FS + JO;

    // Prepare jobOutput dir for output sandbox
    try {
        LOG.debug("Creating job output directory: '" + outputSandbox + "'");
        File outputSandboxDir = new File(outputSandbox);
        if (!outputSandboxDir.exists()) {
            LOG.debug("Creating job output directory");
            outputSandboxDir.mkdir();
            LOG.debug("Job output successfully created");
        } else {
            // Directory altready exists; clean all its content
            LOG.debug("Cleaning job output directory");
            FileUtils.cleanDirectory(outputSandboxDir);
            LOG.debug("Successfully cleaned job output directory");
        }
    } catch (IOException ex) {
        LOG.error("Unable to create output directory  '" + outputSandbox + "' for task having id: "
                + toscaCommand.getTaskId());
    }
}

From source file:com.emarsys.dyson.storage.DefaultDysonStorage.java

/**
 * Removes all files from the incoming directory.
 * /*from   w  w w.ja va2  s  .c  o  m*/
 * TODO implement locking with the {@link IncomingStorageMessageListener}s
 * @throws IOException 
 */
public void clearIncomingDir() throws IOException {
    log.info("cleaning incoming dir \'{}\'", this.incomingDirName);
    FileUtils.cleanDirectory(new File(this.incomingDirName));
}

From source file:com.taobao.android.apatch.ApkPatch.java

public File doPatch() throws PatchException {
    try {/*from w w w .  ja va 2s  .c o m*/
        File aptchFolder = new File(out, name);
        File smaliDir = new File(aptchFolder, "smali");
        if (!smaliDir.exists()) {
            smaliDir.mkdirs();
        }
        try {
            FileUtils.cleanDirectory(smaliDir);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        File dexFile = new File(aptchFolder, "diff.dex");
        if (dexFile.exists() && !dexFile.delete()) {
            throw new RuntimeException("diff.dex can't be removed.");
        }
        File outFile = new File(aptchFolder, "diff" + SUFFIX);
        if (outFile.exists() && !outFile.delete()) {
            throw new RuntimeException("diff" + SUFFIX + " can't be removed.");
        }

        currentTimeStamp = System.currentTimeMillis();
        DexDiffer dexDiffer = new DexDiffer(baseFiles, newFiles, 19);
        // ???
        if ((this.filterPath != null) && !(this.filterPath.equals(""))) {
            dexDiffer.createFilter(this.filterPath);
        }
        //diff
        DexDiffInfo info = dexDiffer.doDiff();
        dexDiffer.setDexDiffFilter(new AndFixFilterImpl(info));

        //diffFilter
        dexDiffer.dexFilter();

        info.update();
        //json
        if (null != diffFile && null != diffJsonFile) {
            info.writeToFile(name, diffFile, diffJsonFile);
        }
        //?dex
        classes = SmaliDiffUtils.buildCode(smaliDir, dexFile, info);
        if (null == classes || classes.size() <= 0) {
            return null;
        }

        //?dex
        if (APatchTool.debug) {
            PatchMethodTool.modifyMethod(dexFile.getAbsolutePath(), dexFile.getAbsolutePath(), true);
        }

        File smaliDir2 = new File(aptchFolder, "smali2");
        if (!smaliDir2.exists()) {
            smaliDir2.mkdirs();
        }
        try {
            FileUtils.cleanDirectory(smaliDir2);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        prepareClasses = buildPrepareClass(smaliDir2, newFiles, info);
        DexDiffInfo.release();
        build(outFile, dexFile);
        File file = release(aptchFolder, dexFile, outFile);
        release();
        return file;
    } catch (Exception e) {
        throw new PatchException(e);
    }
}

From source file:architecture.ee.web.attachment.DefaultImageManager.java

protected synchronized File getImageDir() {
    if (imageDir == null) {
        imageDir = ApplicationHelper.getRepository().getFile("images");
        if (!imageDir.exists()) {
            boolean result = imageDir.mkdir();
            if (!result)
                log.error((new StringBuilder()).append("Unable to create image directory: '").append(imageDir)
                        .append("'").toString());

            getImageCacheDir(); // new File(imageDir, "cache");
            getImageTempDir();//from  ww  w.  ja  va 2s . c o  m
        } else {
            File dir = getImageTempDir();
            try {
                FileUtils.cleanDirectory(dir);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return imageDir;
}

From source file:com.emarsys.dyson.storage.DefaultDysonStorage.java

/**
 * Removes all files from the processed directory.
 * @throws IOException //from   w ww .j a v a2 s .  co m
 */
public void clearProcessedDir() throws IOException {
    synchronized (this.fileCopyMonitor) {
        log.info("cleaning processed dir \'{}\'", this.processedDirName);
        FileUtils.cleanDirectory(new File(this.processedDirName));
    }
}

From source file:com.linkedin.databus.core.TestDbusEventBufferAppendEvents.java

private File initMmapDir(String path) throws Exception {
    File d = new File(path);
    if (d.exists()) {
        FileUtils.cleanDirectory(d);
    } else {/*from   w  w w.j a v  a 2s.  com*/
        d.mkdir();
    }
    d.deleteOnExit();
    return d;
}

From source file:com.uwsoft.editor.controlles.ResolutionManager.java

public void rePackProjectImages(ResolutionEntryVO resEntry) {
    TexturePacker.Settings settings = new TexturePacker.Settings();

    settings.flattenPaths = true;//from  w w  w .j a  v a 2s .  c o  m
    //        settings.maxHeight = getMinSquareNum(resEntry.height);
    //        settings.maxWidth = getMinSquareNum(resEntry.height);
    settings.maxHeight = Integer.parseInt(dataManager.getCurrentProjectVO().texturepackerHeight);
    settings.maxWidth = Integer.parseInt(dataManager.getCurrentProjectVO().texturepackerWidth);
    settings.filterMag = Texture.TextureFilter.Linear;
    settings.filterMin = Texture.TextureFilter.Linear;

    TexturePacker tp = new TexturePacker(settings);

    String sourcePath = dataManager.getCurrentWorkingPath() + "/"
            + dataManager.getCurrentProjectVO().projectName + "/assets/" + resEntry.name + "/images";
    String outputPath = dataManager.getCurrentWorkingPath() + "/"
            + dataManager.getCurrentProjectVO().projectName + "/assets/" + resEntry.name + "/pack";

    FileHandle sourceDir = new FileHandle(sourcePath);
    File outputDir = new File(outputPath);

    try {
        FileUtils.forceMkdir(outputDir);
        FileUtils.cleanDirectory(outputDir);
    } catch (IOException e) {
        e.printStackTrace();
    }

    for (FileHandle entry : sourceDir.list()) {
        String filename = entry.file().getName();
        String extension = filename.substring(filename.lastIndexOf(".") + 1, filename.length()).toLowerCase();
        if (extension.equals("png")) {
            tp.addImage(entry.file());
        }
    }

    tp.pack(outputDir, "pack");
}