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

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

Introduction

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

Prototype

public static void forceDelete(File file) throws IOException 

Source Link

Document

Deletes a file.

Usage

From source file:com.orange.mmp.i18n.helpers.DefaultInternationalizationManager.java

/**
 * Removes a MessageSource from a module
 * /*from  w w  w  .ja v  a  2 s  . c o m*/
 * @param module The module owning the MessageSource
 * @throws MMPException
 */
private void removeModuleMessageSource(Module module) throws MMPException {
    MMPConfig moduleConfiguration = ModuleContainerFactory.getInstance().getModuleContainer()
            .getModuleConfiguration(module);
    if (moduleConfiguration != null && moduleConfiguration.getMessagesource() != null) {
        for (MMPConfig.Messagesource messageSourceConfig : moduleConfiguration.getMessagesource()) {
            if (messageSourceConfig.getOtherAttributes().get(I18N_CONFIG_MS_LOCATION) != null
                    && messageSourceConfig.getOtherAttributes().get(I18N_CONFIG_MS_BASENAME) != null) {
                String messageSourceName = messageSourceConfig.getName();
                try {
                    FileUtils.forceDelete(new File(this.messageBasePath + "/" + messageSourceName));
                } catch (IOException ioe) {
                    //NOP
                }
                this.messageSourceMap.remove(messageSourceName);
            }
        }
    }
}

From source file:de.blizzy.documentr.markdown.macro.GroovyMacroScanner.java

public void deleteMacro(String name) throws IOException {
    File file = new File(macrosDir, name + ".groovy"); //$NON-NLS-1$
    FileUtils.forceDelete(file);
}

From source file:io.druid.indexer.DeterminePartitionsJobTest.java

@After
public void tearDown() throws Exception {
    FileUtils.forceDelete(dataFile);
    FileUtils.deleteDirectory(tmpDir);
}

From source file:fr.logfiletoes.ElasticSearchTest.java

@Test
public void fail2ban() throws IOException, InterruptedException {
    File data = Files.createTempDirectory("it_es_data-").toFile();
    Settings settings = ImmutableSettings.settingsBuilder().put("path.data", data.toString())
            .put("cluster.name", "IT-0002").build();
    Node node = NodeBuilder.nodeBuilder().local(true).settings(settings).build();
    Client client = node.client();//from   w w w  .  j a  v  a  2  s .  c  o  m
    node.start();
    Config config = new Config("./src/test/resources/fail2ban.json");
    List<Unit> units = config.getUnits();
    assertEquals(1, units.size());
    units.get(0).start();

    // Wait store log
    Thread.sleep(3000);

    // Search log
    SearchResponse response = client.prepareSearch("system").setSearchType(SearchType.DEFAULT)
            .setQuery(QueryBuilders.matchQuery("message", "58.218.204.248")).setSize(1000)
            .addSort("@timestamp", SortOrder.ASC).execute().actionGet();
    if (LOG.isLoggable(Level.FINEST)) {
        for (SearchHit hit : response.getHits().getHits()) {
            LOG.finest("-----------------");
            hit.getSource().forEach((key, value) -> {
                LOG.log(Level.FINEST, "{0} = {1}", new Object[] { key, value });
            });
        }
    }

    // Get information need to test
    assertEquals(6, response.getHits().getHits().length);
    assertEquals("Found 58.218.204.248", response.getHits().getHits()[0].getSource().get("message").toString());
    assertEquals("Ban 58.218.204.248", response.getHits().getHits()[5].getSource().get("message").toString());

    // wait request
    Thread.sleep(10000);

    // Close tailer
    units.get(0).stop();

    // Close ElasticSearch
    node.close();

    // Clean data directory
    FileUtils.forceDelete(data);
}

From source file:de.blizzy.backup.backup.BackupRun.java

private void removeOldDatabaseBackups() {
    File outputFolder = new File(settings.getOutputFolder());
    File dbBackupRootFolder = new File(outputFolder, "$db-backup"); //$NON-NLS-1$
    if (dbBackupRootFolder.isDirectory()) {
        List<Long> timestamps = new ArrayList<>();
        for (File f : dbBackupRootFolder.listFiles()) {
            if (f.isDirectory()) {
                timestamps.add(Long.valueOf(f.getName()));
            }/*from   ww  w.  ja v  a 2s.c o m*/
        }
        if (timestamps.size() > 19) {
            Collections.sort(timestamps);
            Collections.reverse(timestamps);
            for (int i = 19; i < timestamps.size(); i++) {
                long timestamp = timestamps.get(i).longValue();
                File folder = new File(dbBackupRootFolder, String.valueOf(timestamp));
                try {
                    FileUtils.forceDelete(folder);
                } catch (IOException e) {
                    BackupPlugin.getDefault().logError("error while deleting old database backup folder: " + //$NON-NLS-1$
                            folder.getAbsolutePath(), e);
                    fireBackupErrorOccurred(e, BackupErrorEvent.Severity.WARNING);
                }
            }
        }
    }
}

From source file:edu.ucsb.eucalyptus.storage.fs.FileSystemStorageManager.java

public void deleteObject(String bucket, String object) throws IOException {
    File oldObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + object);
    if (oldObjectFile.exists()) {
        FileUtils.forceDelete(oldObjectFile);
        //            if (!objectFile.delete()) {
        //                throw new IOException("Unable to delete: " + objectFile.getAbsolutePath());
        //            }
    }//from w  ww.j  a  v a  2s.  co  m
}

From source file:com.btoddb.fastpersitentqueue.JournalMgr.java

private void removeJournal(JournalDescriptor desc) {
    journalLock.writeLock().lock();/*from   www . j a v a2s  .c o m*/
    try {
        journalIdMap.remove(desc.getId());
        try {
            FileUtils.forceDelete(desc.getFile().getFile());
        } catch (IOException e) {
            logger.error("could not delete journal file, {} - will not try again",
                    desc.getFile().getFile().getAbsolutePath());
        }
    } finally {
        journalLock.writeLock().unlock();
    }

    numberOfEntries.addAndGet(-desc.getFile().getNumberOfEntries());
    journalsRemoved.incrementAndGet();
    logger.debug("journal, {}, removed", desc.getId());
}

From source file:jahirfiquitiva.iconshowcase.utilities.ZooperIconFontsHelper.java

private String delete() throws IOException {
    File f = this.mFixed.get(this.mCancelIndex);
    String n = f.getName();//  www.  ja v  a 2s  .  c  om
    FileUtils.forceDelete(f);
    return n;
}

From source file:com.docd.purefm.test.CommandLineFileTest.java

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    FileUtils.forceDelete(testDir);
}

From source file:de.interactive_instruments.ShapeChange.Target.ReplicationSchema.ReplicationXmlSchema.java

@Override
public void initialise(PackageInfo p, Model m, Options o, ShapeChangeResult r, boolean diagOnly)
        throws ShapeChangeAbortException {

    schemaPi = p;/*from   w w w .  j  av  a2s  .  co m*/
    model = m;
    options = o;
    result = r;
    diagnosticsOnly = diagOnly;

    result.addDebug(this, 1, schemaPi.name());

    outputDirectory = options.parameter(this.getClass().getName(), "outputDirectory");
    if (outputDirectory == null)
        outputDirectory = options.parameter("outputDirectory");
    if (outputDirectory == null)
        outputDirectory = options.parameter(".");

    outputFilename = schemaPi.name().replace("/", "_").replace(" ", "_") + ".xsd";

    // Check if we can use the output directory; create it if it
    // does not exist
    outputDirectoryFile = new File(outputDirectory);
    boolean exi = outputDirectoryFile.exists();
    if (!exi) {
        try {
            FileUtils.forceMkdir(outputDirectoryFile);
        } catch (IOException e) {
            result.addError(null, 600, e.getMessage());
            e.printStackTrace(System.err);
        }
        exi = outputDirectoryFile.exists();
    }
    boolean dir = outputDirectoryFile.isDirectory();
    boolean wrt = outputDirectoryFile.canWrite();
    boolean rea = outputDirectoryFile.canRead();
    if (!exi || !dir || !wrt || !rea) {
        result.addFatalError(null, 601, outputDirectory);
        throw new ShapeChangeAbortException();
    }

    File outputFile = new File(outputDirectoryFile, outputFilename);

    // check if output file already exists - if so, attempt to delete it
    exi = outputFile.exists();
    if (exi) {

        result.addInfo(this, 3, outputFilename, outputDirectory);

        try {
            FileUtils.forceDelete(outputFile);
            result.addInfo(this, 4);
        } catch (IOException e) {
            result.addInfo(null, 600, e.getMessage());
            e.printStackTrace(System.err);
        }
    }

    // identify map entries defined in the target configuration
    List<ProcessMapEntry> mapEntries = options.getCurrentProcessConfig().getMapEntries();

    if (mapEntries == null || mapEntries.isEmpty()) {

        result.addFatalError(this, 9);
        throw new ShapeChangeAbortException();

    } else {

        for (ProcessMapEntry pme : mapEntries) {
            this.mapEntryByType.put(pme.getType(), pme);
        }
    }

    // reset processed flags on all classes in the schema
    for (Iterator<ClassInfo> k = model.classes(schemaPi).iterator(); k.hasNext();) {
        ClassInfo ci = k.next();
        ci.processed(getTargetID(), false);
    }

    // ======================================
    // Parse configuration parameters
    // ======================================

    objectIdentifierFieldName = options.parameter(this.getClass().getName(),
            PARAM_OBJECT_IDENTIFIER_FIELD_NAME);
    if (objectIdentifierFieldName == null || objectIdentifierFieldName.trim().length() == 0) {
        objectIdentifierFieldName = DEFAULT_OBJECT_IDENTIFIER_FIELD_NAME;
    }

    suffixForPropWithFeatureValueType = options.parameter(this.getClass().getName(),
            PARAM_SUFFIX_FOR_PROPERTIES_WITH_FEATURE_VALUE_TYPE);
    if (suffixForPropWithFeatureValueType == null || suffixForPropWithFeatureValueType.trim().length() == 0) {
        suffixForPropWithFeatureValueType = "";
    }

    suffixForPropWithObjectValueType = options.parameter(this.getClass().getName(),
            PARAM_SUFFIX_FOR_PROPERTIES_WITH_OBJECT_VALUE_TYPE);
    if (suffixForPropWithObjectValueType == null || suffixForPropWithObjectValueType.trim().length() == 0) {
        suffixForPropWithObjectValueType = "";
    }

    targetNamespaceSuffix = options.parameter(this.getClass().getName(), PARAM_TARGET_NAMESPACE_SUFFIX);
    if (targetNamespaceSuffix == null || objectIdentifierFieldName.trim().length() == 0) {
        targetNamespaceSuffix = "";
    }

    String defaultSizeByConfig = options.parameter(this.getClass().getName(), PARAM_SIZE);
    if (defaultSizeByConfig != null) {
        try {
            defaultSize = Integer.parseInt(defaultSizeByConfig);
        } catch (NumberFormatException e) {
            MessageContext mc = result.addWarning(this, 8, PARAM_SIZE, e.getMessage());
            mc.addDetail(this, 0);
        }
    }

    // ======================================
    // Set up the document and create root
    // ======================================

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(true);
    dbf.setAttribute(Options.JAXP_SCHEMA_LANGUAGE, Options.W3C_XML_SCHEMA);
    DocumentBuilder db;
    try {
        db = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        result.addFatalError(null, 2);
        throw new ShapeChangeAbortException();
    }
    document = db.newDocument();

    root = document.createElementNS(Options.W3C_XML_SCHEMA, "schema");
    document.appendChild(root);

    addAttribute(root, "xmlns", Options.W3C_XML_SCHEMA);
    addAttribute(root, "elementFormDefault", "qualified");

    addAttribute(root, "version", schemaPi.version());
    targetNamespace = schemaPi.targetNamespace() + targetNamespaceSuffix;
    addAttribute(root, "targetNamespace", targetNamespace);
    addAttribute(root, "xmlns:" + schemaPi.xmlns(), targetNamespace);

    hook = document.createComment("XML Schema document created by ShapeChange - http://shapechange.net/");
    root.appendChild(hook);
}