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:ca.uviccscu.lp.utils.Utils.java

public static void cleanupDir() throws IOException {
    FileUtils.forceDelete(new File(Shared.workingDirectory));
    //FileUtils.deleteDirectory(new File(Shared.workingDirectory));

    //FileUtils.forceDeleteOnExit(new File(Shared.workingDirectory));
    //File f = new File(Shared.workingDirectory);
    //f.deleteOnExit();
}

From source file:com.collective.celos.ci.mode.TestTask.java

@Override
public void start() throws Throwable {
    try {//  w  w w  .  jav  a  2  s. c  om
        List<Future> futures = submitTestRuns();
        waitForCompletion(futures);
    } finally {
        if (celosCiTempDir.exists() && allTestCasesDeletedTheirData()) {
            FileUtils.forceDelete(celosCiTempDir);
        }
    }
}

From source file:de.fabianonline.telegram_backup.ApiStorage.java

public void deleteAuthKey() {
    if (this.do_save) {
        try {//from   w  w w .  jav a  2s  .c  o  m
            FileUtils.forceDelete(this.file_auth_key);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:hoot.services.ingest.MultipartSerializerTest.java

@Test
@Category(UnitTest.class)
public void TestserializeFGDB() throws Exception {
    String jobId = "123-456-789";
    String wkdirpath = homeFolder + "/upload/" + jobId;
    File workingDir = new File(wkdirpath);
    FileUtils.forceMkdir(workingDir);/*from   w ww . j a va 2  s  .  c  om*/
    org.junit.Assert.assertTrue(workingDir.exists());

    List<FileItem> fileItemsList = new ArrayList<FileItem>();

    FileItemFactory factory = new DiskFileItemFactory(16, null);
    String textFieldName = "textField";

    FileItem item = factory.createItem(textFieldName, "application/octet-stream", true,
            "fgdbTest.gdb/dummy1.gdbtable");

    String textFieldValue = "0123456789";
    byte[] testFieldValueBytes = textFieldValue.getBytes();

    OutputStream os = item.getOutputStream();
    os.write(testFieldValueBytes);
    os.close();

    File out = new File(wkdirpath + "/buffer.tmp");
    item.write(out);
    fileItemsList.add(item);
    org.junit.Assert.assertTrue(out.exists());

    Map<String, String> uploadedFiles = new HashMap<String, String>();
    Map<String, String> uploadedFilesPaths = new HashMap<String, String>();

    _ms._serializeFGDB(fileItemsList, jobId, uploadedFiles, uploadedFilesPaths);

    org.junit.Assert.assertEquals("GDB", uploadedFiles.get("fgdbTest"));
    org.junit.Assert.assertEquals("fgdbTest.gdb", uploadedFilesPaths.get("fgdbTest"));

    File fgdbpath = new File(wkdirpath + "/fgdbTest.gdb");
    org.junit.Assert.assertTrue(fgdbpath.exists());

    File content = new File(wkdirpath + "/fgdbTest.gdb/dummy1.gdbtable");
    org.junit.Assert.assertTrue(content.exists());

    FileUtils.forceDelete(workingDir);
}

From source file:functionaltests.workflow.TestJobLegacySchemas.java

private void prepareDataspaceFolder() throws IOException {
    File ds = new File(PAResourceManagerProperties.RM_HOME.getValueAsString(),
            "/scheduler/scheduler-server/build/JobLegacySchemas_dataspace");

    if (ds.exists()) {
        File[] filesToDelete = ds.listFiles(new FilenameFilter() {
            @Override//  w  ww  .j  a  v  a 2 s  .  c o m
            public boolean accept(File dir, String name) {
                return name.startsWith("myfileout") || name.endsWith(".log");
            }
        });
        for (File f : filesToDelete) {
            FileUtils.forceDelete(f);
        }
    } else {
        FileUtils.forceMkdir(ds);
    }
}

From source file:net.ontopia.topicmaps.db2tm.DB2TMRescanTestCase.java

@Test
public void testFile() throws IOException {
    TestFileUtils.verifyDirectory(base, "out");

    String name = filename.substring(0, filename.length() - ".xml".length());

    // Path to the config file.
    File cfg = TestFileUtils.getTransferredTestInputFile(testdataDirectory, "in/rescan", filename);

    // Path to the topic map seed.
    String in = TestFileUtils.getTestInputFile(testdataDirectory, "in/rescan", name + ".ltm");

    // Path to the cxtm version of the output topic map.
    File cxtm = TestFileUtils.getTestOutputFile(testdataDirectory, "out", "rescan-" + name + ".cxtm");

    // Path to the baseline.
    String baseline = TestFileUtils.getTestInputFile(testdataDirectory, "baseline", "rescan-" + name + ".cxtm");

    // Import the topic map seed.
    TopicMapIF topicmap = ImportExportUtils.getReader(in).read();
    LocatorIF baseloc = topicmap.getStore().getBaseAddress();

    // Run DB2TM processes
    RelationMapping mapping = RelationMapping.read(cfg);

    // Prepare files
    File target = TestFileUtils.getTestOutputFile(testdataDirectory, "in", "rescan", name + ".csv");
    File before = TestFileUtils.getTestOutputFile(testdataDirectory, "in", "rescan", name + "-before.csv");
    File after = TestFileUtils.getTestOutputFile(testdataDirectory, "in", "rescan", name + "-after.csv");

    // Copy before-file
    FileUtils.copyFile(before, target);/*from  w w  w. java  2s.c o m*/

    // Add relations topic topicmap
    Processor.addRelations(mapping, null, topicmap, baseloc);

    // Copy after-file
    FileUtils.copyFile(after, target);

    // Rescan relations
    Processor.synchronizeRelations(mapping, null, topicmap, baseloc);

    // Get rid of temporary target file
    FileUtils.forceDelete(after);

    // Export the result topic map to ltm, for manual inspection purposes.
    if (DEBUG_LTM) {
        File ltm = TestFileUtils.getTestOutputFile(testdataDirectory, "out", "rescan-" + name + ".ltm");
        new LTMTopicMapWriter(ltm).write(topicmap);
    }

    // Export the result topic map to cxtm
    new CanonicalXTMWriter(cxtm).write(topicmap);

    // Check that the cxtm output matches the baseline.
    Assert.assertTrue("The canonicalized conversion from " + filename + " does not match the baseline: " + cxtm
            + " " + baseline, TestFileUtils.compareFileToResource(cxtm, baseline));
}

From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePublicKeyDataProvider.java

@Test
@Ignore("canRead()/canWrite() do not work on Win; setReadable()/setWritable() do not work on some Macs.")
public void testGetEncryptedPublicKeyData02() throws IOException {
    final String fileName = "testGetEncryptedPublicKeyData02.key";
    File file = new File(fileName);
    file = file.getCanonicalFile();/*from   www .  j  a  v a2  s. c  om*/

    if (file.exists())
        FileUtils.forceDelete(file);

    byte[] data = new byte[] { 0x01, 0x71, 0x33 };

    FileUtils.writeByteArrayToFile(file, data);

    try {
        assertTrue("Setting the file to not-readable should have succeeded.", file.setReadable(false, false));
        assertFalse("The file should not be readable.", file.canRead());
        assertTrue("The file should still be writable.", file.canWrite());

        FilePublicKeyDataProvider provider = new FilePublicKeyDataProvider(file);

        try {
            provider.getEncryptedPublicKeyData();
            fail("Expected exception KeyNotFoundException.");
        } catch (KeyNotFoundException e) {
            assertNotNull("The cause should not be null.", e.getCause());
        }
    } finally {
        FileUtils.forceDelete(file);
    }
}

From source file:android.databinding.compilationTest.BaseCompilationTest.java

@Before
public void clear() throws IOException {
    if (testFolder.exists()) {
        FileUtils.forceDelete(testFolder);
    }
}

From source file:com.hortonworks.amstore.view.StoreApplicationView.java

public void deletePackageFile() throws IOException {
    String packagePath = getPackageFilepath();
    FileUtils.forceDelete(new File(packagePath));
}

From source file:it.greenvulcano.util.file.FileManager.java

/**
 * Delete the file/directory from the local file system.<br>
 * The filePattern may be a regular expression: in this case, all
 * the file names matching the pattern will be deleted.<br>
 *
 * @param targetPath//from w ww .j  a v a 2 s .  co m
 *            Absolute pathname of the target file/directory.
 * @param filePattern
 *            A regular expression defining the name of the files to be deleted. Used only if
 *            targetPath identify a directory.
 * @throws Exception
 */
public static void rm(String targetPath, String filePattern) throws Exception {
    File target = new File(targetPath);
    if (!target.isAbsolute()) {
        throw new IllegalArgumentException("The pathname of the target file is NOT absolute: " + targetPath);
    }
    if (target.isDirectory()) {
        if ((filePattern == null) || filePattern.equals("")) {
            logger.debug("Removing directory " + target.getAbsolutePath());
            FileUtils.deleteDirectory(target);
        } else if (filePattern.equals(".*")) {
            logger.debug("Removing directory " + target.getAbsolutePath() + " content.");
            FileUtils.cleanDirectory(target);
        } else {
            Set<FileProperties> files = ls(targetPath, filePattern);
            for (FileProperties file : files) {
                logger.debug("Removing file/directory " + file.getName() + " from directory "
                        + target.getAbsolutePath());
                FileUtils.forceDelete(new File(target, file.getName()));
            }
        }
    } else {
        logger.debug("Removing file " + target.getAbsolutePath());
        FileUtils.forceDelete(target);
    }
}