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.frostwire.android.gui.MainApplication.java

private static void cleanTemp() {
    try {/*from   w w w.  j  av  a 2s  .co  m*/
        File tmp = Platforms.get().systemPaths().temp();
        if (tmp.exists()) {
            FileUtils.cleanDirectory(tmp);
        }
    } catch (Throwable e) {
        LOG.error("Error during setup of temp directory", e);
    }
}

From source file:io.ucoin.ucoinj.elasticsearch.Main.java

protected void initI18n(Configuration config) throws IOException {

    // --------------------------------------------------------------------//
    // init i18n//  w  ww  .  j  a  va 2s . co  m
    // --------------------------------------------------------------------//
    File i18nDirectory = new File(config.getDataDirectory(), "i18n");
    if (i18nDirectory.exists()) {
        // clean i18n cache
        FileUtils.cleanDirectory(i18nDirectory);
    }

    FileUtils.forceMkdir(i18nDirectory);

    if (log.isDebugEnabled()) {
        log.debug("I18N directory: " + i18nDirectory);
    }

    Locale i18nLocale = config.getI18nLocale();

    if (log.isInfoEnabled()) {
        log.info(String.format("Starts i18n with locale [%s] at [%s]", i18nLocale, i18nDirectory));
    }
    I18n.init(new UserI18nInitializer(i18nDirectory, new DefaultI18nInitializer(getI18nBundleName())),
            i18nLocale);
}

From source file:com.krzysztofzabinski.publication1.Remover.java

public static void writeResultToFile() throws IOException {
    FileUtils.cleanDirectory(new File("output/"));
    for (int i = 0; i < inputRules.size(); i++) {
        try (FileWriter writeFile = new FileWriter("output/" + inputFilesRules[i].getName())) {
            for (int j = 0; j < inputRules.get(i).size(); j++) {
                writeFile.append(inputRules.get(i).get(j) + "\n");
            }//  ww w  .j  a  va 2  s.  c  om
            writeFile.close();
        }
    }
}

From source file:edu.ku.brc.specify.utilapps.ERDVisualizer.java

public ERDVisualizer() {
    boolean showTreeHierarchy = false;

    Locale.setDefault(currLang);//from  w  ww. ja  va 2s .c  om
    UIRegistry.setResourceLocale(currLang);

    Vector<DBTableInfo> tables = DBTableIdMgr.getInstance().getTables();
    Collections.sort(tables);

    SchemaLocalizerXMLHelper schemaXMLHelper = new SchemaLocalizerXMLHelper(SpLocaleContainer.CORE_SCHEMA,
            DBTableIdMgr.getInstance());
    schemaXMLHelper.load(true);
    schemaXMLHelper.setTitlesIntoSchema();

    ERDTable.setDisplayType(showTreeHierarchy ? ERDTable.DisplayType.Title : ERDTable.DisplayType.All);

    tblTracker = new TableTracker();

    String schemDirName = adjustFileNameForLocale("schema%s");

    final File localSchemaDir = new File(schemDirName);
    if (!localSchemaDir.exists()) {
        localSchemaDir.mkdir();
    } else {
        try {
            FileUtils.cleanDirectory(localSchemaDir);

        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, ex);
            ex.printStackTrace();
        }
    }

    this.schemaDir = localSchemaDir;

    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    p.add(mainPanel = new ERDPanel(tblTracker), BorderLayout.CENTER);
    setContentPane(new JScrollPane(p));
    p.setBackground(Color.WHITE);
    mainPanel.setBackground(Color.WHITE);

    try {
        File templateFile = new File(
                UIRegistry.getDefaultWorkingPath() + File.separator + "site/template.html");
        mapTemplate = FileUtils.readFileToString(templateFile);

    } catch (IOException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, ex);
        ex.printStackTrace();
    }

    if (StringUtils.isEmpty(mapTemplate)) {
        System.err.println("The template file is empty!");
    }

    try {
        File srcDir = new File(UIRegistry.getDefaultWorkingPath() + File.separator + "site");
        for (File f : srcDir.listFiles()) {
            if (!f.getName().startsWith(".")) {
                File dst = new File(UIRegistry.getDefaultWorkingPath() + File.separator + schemDirName
                        + File.separator + f.getName());
                if (!FilenameUtils.getExtension(f.getName()).toLowerCase().equals("html")) {
                    FileUtils.copyFile(f, dst);
                }
            }
        }
    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, ex);
        ex.printStackTrace();
    }

    // Choose what to display

    if (!showTreeHierarchy) {
        advance();

        int period = isDoShadow() ? 10000 : 1000;
        int delay = isDoShadow() ? 5000 : 1000;
        timer = new Timer();

        if (true)

        {
            timer.scheduleAtFixedRate(new TimerTask() {
                public void run() {
                    advance();
                }
            }, period, delay);
        }
    } else {
        ERDTable.setDisplayType(ERDTable.DisplayType.Title);

        //this.tblTracker.setFont(this.tblTracker.getFont().deriveFont((float)10.0));
        ERDTable root = null;

        boolean doCollectionSchema = true;

        if (doCollectionSchema) {
            root = tblTracker.getTable("Discipline");

            //                                                skip,  processKids, alwaysAKid, processAnyRel, okWhenParent
            tblTracker.addNodeInfo("Agent", false, true, true, false, null);
            tblTracker.addNodeInfo("Determination", false, true, true, true, null);
            tblTracker.addNodeInfo("ConservDescription", false, true, true, true, null);

            tblTracker.addNodeInfo("Attachment", true, true, true, false, null);
            tblTracker.addNodeInfo("AttributeDef", true, true, true, false, null);
            tblTracker.addNodeInfo("SpAppResourceDir", true, true, true, false, null);
            tblTracker.addNodeInfo("SpLocaleContainer", true, true, true, false, null);
            tblTracker.addNodeInfo("DeaccessionPreparation", true, true, true, false, null);
            tblTracker.addNodeInfo("OtherIdentifier", true, true, true, false, null);
            tblTracker.addNodeInfo("CollectionRelationship", true, true, true, false, null);
            tblTracker.addNodeInfo("ProjectCollectionObject", true, true, true, false, null);
            tblTracker.addNodeInfo("CollectionObjectAttr", true, true, true, false, null);
            tblTracker.addNodeInfo("CollectionObjectAttachment", true, true, true, false, null);
            tblTracker.addNodeInfo("ConservDescriptionAttachment", true, true, true, false, null);
            tblTracker.addNodeInfo("ConservEventAttachment", true, true, true, false, null);

            // No Kids
            tblTracker.addNodeInfo("Discipline", false, false, true, false, null);
            tblTracker.addNodeInfo("Collection", false, false, true, false, null);
            tblTracker.addNodeInfo("Taxon", false, false, true, false, null);
            tblTracker.addNodeInfo("TaxonCitation", false, false, true, false, null);
            //                tblTracker.addNodeInfo("DeterminationCitation",  false, false, true,  false, null);
            tblTracker.addNodeInfo("ReferenceWork", false, false, true, false, null);
            tblTracker.addNodeInfo("Journal", false, false, true, false, null);
            tblTracker.addNodeInfo("CollectingEvent", false, false, true, false, null);
            tblTracker.addNodeInfo("Locality", false, false, true, false, null);
            tblTracker.addNodeInfo("Geography", false, false, true, false, null);
            tblTracker.addNodeInfo("PaleoContext", false, false, true, false, null);
            tblTracker.addNodeInfo("LithoStrat", false, false, true, false, null);
            tblTracker.addNodeInfo("GeologicTimePeriod", false, false, true, false, null);
            tblTracker.addNodeInfo("CollectionObjectCitation", false, false, true, false, null);
            tblTracker.addNodeInfo("Accession", false, false, true, false, null);
            tblTracker.addNodeInfo("AccessionAuthorization", false, false, true, false, null);
            tblTracker.addNodeInfo("AccessionAgent", false, false, true, false, null);
            tblTracker.addNodeInfo("Agent", false, false, true, false, null);
            tblTracker.addNodeInfo("Preparation", false, false, true, false, null);
            tblTracker.addNodeInfo("PrepType", false, false, true, false, null);
            tblTracker.addNodeInfo("RepositoryAgreement", false, false, true, false, null);
            tblTracker.addNodeInfo("ConservEvent", false, false, true, false, null);

            tblTracker.addNodeInfo("DNASequence", false, false, true, false, null);
            tblTracker.addNodeInfo("TreatmentEvent", false, false, true, false, null);
            tblTracker.addNodeInfo("Ipm", false, false, true, false, null);
            tblTracker.addNodeInfo("FieldNotebook", false, false, true, false, null);
            tblTracker.addNodeInfo("FieldNotebookPageSet", false, false, true, false, null);
            tblTracker.addNodeInfo("FieldNotebookPage", false, false, true, false, null);

            NodeInfo det = tblTracker.getNodeInfo("Determination");
            det.addKid(tblTracker.getTable("Taxon"));
            //                det.addKid(tblTracker.getTable("DeterminationStatus"));

            NodeInfo ni = tblTracker.getNodeInfo("Taxon");
            ni.addKid(tblTracker.getTable("TaxonCitation"));

            ni = tblTracker.getNodeInfo("Discipline");
            ni.addKid(tblTracker.getTable("Collection"));

            ni = tblTracker.getNodeInfo("Collection");
            ni.addKid(tblTracker.getTable("FieldNotebook"));
            ni.addKid(tblTracker.getTable("CollectionObject"));

            ni = tblTracker.getNodeInfo("CollectionObjectCitation");
            ni.addKid(tblTracker.getTable("ReferenceWork"));

            ni = tblTracker.getNodeInfo("TaxonCitation");
            ni.addKid(tblTracker.getTable("ReferenceWork"));

            ni = tblTracker.getNodeInfo("ReferenceWork");
            ni.setOkToDuplicate(true);
            ni.addKid(tblTracker.getTable("Journal"));

            ni = tblTracker.getNodeInfo("GeologicTimePeriod");
            ni.setOkToDuplicate(true);

            ni = tblTracker.getNodeInfo("Journal");
            ni.setOkToDuplicate(true);

            ni = tblTracker.getNodeInfo("CollectingEvent");
            ni.addKid(tblTracker.getTable("Locality"));

            ni = tblTracker.getNodeInfo("CollectionObject");
            ni.addKid(tblTracker.getTable("CollectingEvent"));
            ni.addKid(tblTracker.getTable("PaleoContext"));
            ni.addKid(tblTracker.getTable("Accession"));
            ni.addKid(tblTracker.getTable("DNASequence"));
            ni.addKid(tblTracker.getTable("TreatmentEvent"));
            ni.addKid(tblTracker.getTable("Ipm"));

            ni = tblTracker.getNodeInfo("Locality");
            ni.addKid(tblTracker.getTable("Geography"));

            ni = tblTracker.getNodeInfo("PaleoContext");
            ni.addKid(tblTracker.getTable("LithoStrat"));
            ni.addKid(tblTracker.getTable("GeologicTimePeriod"));

            ni = tblTracker.getNodeInfo("DeterminationCitation");
            ni.addKid(tblTracker.getTable("ReferenceWork"));

            ni = tblTracker.getNodeInfo("Preparation");
            ni.addKid(tblTracker.getTable("PrepType"));

            ni = tblTracker.getNodeInfo("Accession");
            ni.addKid(tblTracker.getTable("AccessionAuthorization"));
            ni.addKid(tblTracker.getTable("AccessionAgent"));
            ni.addKid(tblTracker.getTable("RepositoryAgreement"));
            //ni.addKid(tblTracker.getTable("Attachment"));
            //protected RepositoryAgreement repositoryAgreement;

            ni = tblTracker.getNodeInfo("ConservEvent");
            ni.addKid(tblTracker.getTable("ConservRecommendation"));

            ni = tblTracker.getNodeInfo("FieldNotebook");
            ni.addKid(tblTracker.getTable("FieldNotebookPageSet"));

            ni = tblTracker.getNodeInfo("FieldNotebookPageSet");
            ni.addKid(tblTracker.getTable("FieldNotebookPage"));

        } else {
            root = tblTracker.getTable("SpAppResourceDir");

            //                                           skip,  processKids, alwaysAKid, processAnyRel, okWhenParent
            //tblTracker.addNodeInfo("Agent",              false, true,        true,       false,         null);

            // No Kids
            tblTracker.addNodeInfo("SpAppResourceData", false, false, true, false, null);
            tblTracker.addNodeInfo("Collection", false, false, true, false, null);
            tblTracker.addNodeInfo("Discipline", false, false, true, false, null);
            tblTracker.addNodeInfo("SpecifyUser", false, false, true, false, null);
            tblTracker.addNodeInfo("SpAppResource", false, false, true, false, null);
            tblTracker.addNodeInfo("SpViewSetObj", false, false, true, false, null);
            tblTracker.addNodeInfo("SpUIViewSet", false, false, true, false, null);
            tblTracker.addNodeInfo("SpUIView", false, false, true, false, null);
            tblTracker.addNodeInfo("SpUIViewDef", false, false, true, false, null);
            tblTracker.addNodeInfo("SpUIAltView", false, false, true, false, null);
            tblTracker.addNodeInfo("SpUIColumn", false, false, true, false, null);
            tblTracker.addNodeInfo("SpUIRow", false, false, true, false, null);
            tblTracker.addNodeInfo("SpUICell", false, false, true, false, null);

            NodeInfo ni = tblTracker.getNodeInfo("SpAppResourceDir");
            ni.addKid(tblTracker.getTable("SpAppResource"));
            ni.addKid(tblTracker.getTable("SpViewSetObj"));
            //ni.addKid(tblTracker.getTable("Collection"));
            //ni.addKid(tblTracker.getTable("Discipline"));
            //ni.addKid(tblTracker.getTable("SpecifyUser"));

            ni = tblTracker.getNodeInfo("SpAppResource");
            ni.addKid(tblTracker.getTable("SpAppResourceData"));

            ni = tblTracker.getNodeInfo("SpViewSetObj");
            ni.addKid(tblTracker.getTable("SpAppResourceData"));
            ni.addKid(tblTracker.getTable("SpUIViewSet"));

            ni = tblTracker.getNodeInfo("SpUIViewSet");
            ni.addKid(tblTracker.getTable("SpUIView"));
            ni.addKid(tblTracker.getTable("SpUIViewDef"));

            ni = tblTracker.getNodeInfo("SpUIView");
            ni.addKid(tblTracker.getTable("SpUIAltView"));

            ni = tblTracker.getNodeInfo("SpUIViewDef");
            ni.addKid(tblTracker.getTable("SpUIColumn"));
            ni.addKid(tblTracker.getTable("SpUIRow"));

            ni = tblTracker.getNodeInfo("SpUIRow");
            ni.addKid(tblTracker.getTable("SpUICell"));
            //ni.addKid(tblTracker.getTable("SpUIViewDef"));

            //ni = tblTracker.getNodeInfo("SpUIAltView");
            //ni.addKid(tblTracker.getTable("SpUIView"));
            //ni.addKid(tblTracker.getTable("SpUIViewDef"));

            ni = tblTracker.getNodeInfo("SpAppResourceData");
            ni.setOkToDuplicate(true);

            if (false) {
                NodeInfo det = tblTracker.getNodeInfo("Determination");
                det.addKid(tblTracker.getTable("Taxon"));
                //                    det.addKid(tblTracker.getTable("DeterminationStatus"));

                ni = tblTracker.getNodeInfo("Taxon");
                ni.addKid(tblTracker.getTable("TaxonCitation"));

                ni = tblTracker.getNodeInfo("CollectionObjectCitation");
                ni.addKid(tblTracker.getTable("ReferenceWork"));

                ni = tblTracker.getNodeInfo("TaxonCitation");
                ni.addKid(tblTracker.getTable("ReferenceWork"));

                ni = tblTracker.getNodeInfo("ReferenceWork");
                ni.setOkToDuplicate(true);
                ni.addKid(tblTracker.getTable("Journal"));

                ni = tblTracker.getNodeInfo("GeologicTimePeriod");
                ni.setOkToDuplicate(true);

                ni = tblTracker.getNodeInfo("Journal");
                ni.setOkToDuplicate(true);

                ni = tblTracker.getNodeInfo("CollectingEvent");
                ni.addKid(tblTracker.getTable("Locality"));

                ni = tblTracker.getNodeInfo("CollectionObject");
                ni.addKid(tblTracker.getTable("CollectingEvent"));
                ni.addKid(tblTracker.getTable("PaleoContext"));
                ni.addKid(tblTracker.getTable("Accession"));

                ni = tblTracker.getNodeInfo("Locality");
                ni.addKid(tblTracker.getTable("Geography"));

                ni = tblTracker.getNodeInfo("PaleoContext");
                ni.addKid(tblTracker.getTable("LithoStrat"));
                ni.addKid(tblTracker.getTable("GeologicTimePeriod"));

                ni = tblTracker.getNodeInfo("DeterminationCitation");
                ni.addKid(tblTracker.getTable("ReferenceWork"));

                ni = tblTracker.getNodeInfo("Preparation");
                ni.addKid(tblTracker.getTable("PrepType"));

                ni = tblTracker.getNodeInfo("Accession");
                ni.addKid(tblTracker.getTable("AccessionAuthorization"));
                ni.addKid(tblTracker.getTable("AccessionAgent"));
                ni.addKid(tblTracker.getTable("RepositoryAgreement"));
            }

        }

        if (false) {
            NodeInfo ni = tblTracker.getNodeInfo("Agent");
            ni.setOkToDuplicate(true);

            String[] toAddAgent = { "CollectionObject", "Accession", "Determination", "Preparation", };
            for (String name : toAddAgent) {
                ni = tblTracker.getNodeInfo(name);
                ni.addKid(tblTracker.getTable("Agent"));
            }
        }

        processAsTree(root, 0);
        mainPanel.addTree(root);

        final SwingWorker worker = new SwingWorker() {
            public Object construct() {
                try {
                    Thread.sleep(3000);

                } catch (Exception ex) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, ex);
                    ex.printStackTrace();
                }
                return null;
            }

            //Runs on the event-dispatching thread.
            public void finished() {
                generate();
                System.out.println("Done.");
            }
        };
        worker.start();
    }

    createIndexFile();
}

From source file:com.seleniumtests.ut.util.squashta.TestTaFolderStructureGenerator.java

/**
 * folder structure generation with java file present in output. We check that it's overwritten
 * @throws IOException/*www.j a  v a 2 s .  c  om*/
 */
@Test(groups = { "squash" })
public void testGenerateStructureWithExistingJavaInOutput() throws IOException {
    File tmpFolder = Paths.get(SeleniumTestsContextManager.getDataPath(), "tmp").toFile();
    File javaFile = Paths
            .get(tmpFolder.getPath(), "src", "squashTA", "resources", "junit", "java", "SeleniumRobotTest.java")
            .toFile();
    FileUtils.writeStringToFile(javaFile, "javaExist");

    TaFolderStructureGenerator structGen = new TaFolderStructureGenerator("core", null,
            tmpFolder.getAbsolutePath());
    try {
        structGen.generateDefaultStructure();
        Assert.assertTrue(javaFile.exists());
        Assert.assertNotEquals(FileUtils.readFileToString(javaFile), "javaExist");
    } finally {
        FileUtils.cleanDirectory(tmpFolder);
        tmpFolder.delete();
    }
}

From source file:de.blizzy.backup.database.Database.java

private void copyFolder(File folder, File targetFolder, boolean zipFiles) throws IOException {
    FileUtils.forceMkdir(targetFolder);// ww w  . j a  va2  s  . co  m
    FileUtils.cleanDirectory(targetFolder);

    for (File file : folder.listFiles()) {
        if (file.isDirectory()) {
            copyFolder(file, new File(targetFolder, file.getName()), zipFiles);
        } else {
            if (zipFiles) {
                Utils.zipFile(file, new File(targetFolder, file.getName() + ".zip")); //$NON-NLS-1$
            } else {
                FileUtils.copyFile(file, new File(targetFolder, file.getName()));
            }
        }
    }
}

From source file:com.goodformobile.build.mobile.GenerateRAPCMojoTest.java

private void setupBuildDirectory(File buildDirectory) throws IOException {
    if (!buildDirectory.exists()) {
        FileUtils.forceMkdir(buildDirectory);
    }/*from   ww w. ja va  2  s.co m*/
    FileUtils.cleanDirectory(buildDirectory);
}

From source file:com.roquahacks.semafor4j.FrameNetService.java

public void cleanTempFiles() {
    try {/*w  w  w.  ja  va 2 s .c  om*/
        FileUtils.cleanDirectory(new File(FrameNetOptions.ABS_PATH_DIR_TEMP));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:de.thischwa.pmcms.view.renderer.ExportRenderer.java

/**
 * Start the export of the static html pages.
 * /*from   w w  w .  java 2 s . co  m*/
 * @throws RuntimeException if an exception is happened during rendering.
 */
@Override
public void run() {
    logger.debug("Entered run.");
    File siteDir = PoPathInfo.getSiteDirectory(this.site);
    if (monitor != null)
        monitor.beginTask(
                String.format("%s: %d", LabelHolder.get("task.export.monitor"), this.renderableObjects.size()),
                this.renderableObjects.size()); //$NON-NLS-1$

    if (CollectionUtils.isEmpty(site.getPages()))
        renderRedirector();

    try {
        FileUtils.cleanDirectory(exportDir);

        // build the directory structure for the renderables
        for (IRenderable ro : renderableObjects) {
            File dir = PathTool.getExportFile(ro, poExtension).getParentFile();
            if (!dir.exists())
                dir.mkdirs();
        }

        // loop through the renderable objects
        renderRenderables();

        if (!exportController.isError() && !isInterruptByUser) {
            logger.debug("Static export successfull!");

            // extra files to copy
            Set<File> filesToCopy = renderData.getFilesToCopy();
            for (File srcFile : filesToCopy) {
                String exportPathPart = srcFile.getAbsolutePath()
                        .substring(siteDir.getAbsolutePath().length() + 1);
                File destFile = new File(exportDir, exportPathPart);
                if (srcFile.isFile())
                    FileUtils.copyFile(srcFile, destFile);
            }
            logger.debug("Extra files successful copied!");

            // generate hashes
            Collection<File> exportedFiles = FileTool.collectFiles(exportDir);
            if (monitor != null) {
                monitor.done();
                monitor.beginTask("Calculate checksums", exportedFiles.size());
            }
            Document dom = ChecksumTool
                    .getDomChecksums(ChecksumTool.get(exportedFiles, exportDir.getAbsolutePath(), monitor));
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            OutputFormat outformat = OutputFormat.createPrettyPrint();
            outformat.setEncoding(Constants.STANDARD_ENCODING);
            XMLWriter writer = new XMLWriter(out, outformat);
            writer.write(dom);
            writer.flush();
            String formatedDomString = out.toString();
            InputStream in = new ByteArrayInputStream(formatedDomString.getBytes());
            Map<InputStream, String> toCompress = new HashMap<InputStream, String>();
            toCompress.put(in, checksumFilename);
            File zipFile = new File(PoPathInfo.getSiteExportDirectory(site),
                    FilenameUtils.getBaseName(checksumFilename) + ".zip");
            Zip.compress(zipFile, toCompress);
            zipFile = null;
        } else
            FileUtils.cleanDirectory(exportDir);
    } catch (Exception e) {
        logger.error("Error while export: " + e.getMessage(), e);
        throw new FatalException("Error while export " + this.site.getUrl() + e.getMessage(), e);
    } finally {
        if (monitor != null)
            monitor.done();
    }
}

From source file:it.geosolutions.geobatch.figis.intersection.Utilities.java

/************
 * Deletes all files and subdirectories under dir.
 * Returns true if all deletions were successful.
 * If a deletion fails, the method stops attempting to delete and returns false.
 * @param dir/*from  w  w w . j a  v  a2s. c om*/
 * @return
 * @throws IOException
 */
static boolean deleteDir(File dir) {

    LOGGER.trace("Deleting dir " + dir);
    try {
        if (dir.exists() && dir.isDirectory()) {
            FileUtils.cleanDirectory(dir);
        }
    } catch (IOException e) {
        LOGGER.error("ERRORE ON DELETING DIR: " + dir.getAbsolutePath());
        LOGGER.error(e.getLocalizedMessage(), e);
    }
    // The directory is now empty so delete it
    return !dir.exists();
}