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:ch.silviowangler.dox.AbstractIntegrationTest.java

protected File createTestFile(final String fileName, final String content) throws IOException {
    File temp = new File(fileName);

    if (temp.exists())
        FileUtils.forceDelete(temp);
    FileUtils.write(temp, content);//from  ww w  .  j a  va 2  s.co m
    assertTrue("Should exist", temp.exists());
    temp.deleteOnExit();

    return temp;
}

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

@Test
public void testGetEncryptedPrivateKeyData01() throws IOException {
    final String fileName = "testGetEncryptedPrivateKeyData01.key";
    File file = new File(fileName);

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

    FilePrivateKeyDataProvider provider = new FilePrivateKeyDataProvider(file);

    try {/*from   w w w.  j a va 2 s  .c  om*/
        provider.getEncryptedPrivateKeyData();
        fail("Expected exception KeyNotFoundException.");
    } catch (KeyNotFoundException e) {
        assertNull("The cause should be null.", e.getCause());
    }
}

From source file:gov.redhawk.sca.efs.server.tests.FileSystemImplTest.java

/**
 * @throws java.lang.Exception//from  w w w  .  j  a v  a 2  s . co  m
 */
@After
public void tearDown() throws Exception {
    this.fileSystem = null;
    final File tempFile = new File(FileSystemImplTest.root, FileSystemImplTest.TEMP_FILE_NAME);
    if (tempFile.exists()) {
        FileUtils.forceDelete(tempFile);
    }

    final File tempDir = new File(FileSystemImplTest.root, FileSystemImplTest.TEMP_DIR_NAME);
    if (tempDir.exists()) {
        FileUtils.deleteDirectory(tempDir);
    }
}

From source file:gov.nih.nci.cacis.ip.mirthconnect.ftp.SFTPSender.java

public void sendDocument(InputStream file, String ftpAddress, String extension) {

    StandardFileSystemManager standardFileSystemManager = new StandardFileSystemManager();
    try {//from w  ww .ja v a2 s. co  m
        final FTPInfo ftpInfo = ftpMapping.getFTPInfo(ftpAddress);
        if (ftpInfo == null) {
            throw new ApplicationRuntimeException("No server config exists for address[ " + ftpAddress + " ]");
        }

        String sftpURI = "sftp://" + ftpInfo.getUserName() + ":" + ftpInfo.getPassword() + "@"
                + ftpInfo.getSite() + "/" + ftpInfo.getRootDirectory();
        String fileName = "IHEXIPFTP-" + UUID.randomUUID() + extension;

        FileSystemOptions fileSystemOptions = new FileSystemOptions();
        SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fileSystemOptions, "no");
        SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fileSystemOptions, true);

        standardFileSystemManager.init();

        FileObject fileObject = standardFileSystemManager.resolveFile(sftpURI + "/" + fileName,
                fileSystemOptions);

        long timestamp = new Date().getTime();
        String tempSftpFile = sftpFileDirectory + "/" + timestamp + ".xml";
        OutputStream out = new FileOutputStream(new File(tempSftpFile));

        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = file.read(bytes)) != -1) {
            out.write(bytes, 0, read);
        }
        file.close();
        out.flush();
        out.close();

        FileObject localFileObject = standardFileSystemManager.resolveFile(tempSftpFile);

        fileObject.copyFrom(localFileObject, Selectors.SELECT_SELF);

        FileUtils.forceDelete(new File(tempSftpFile));

    } catch (Exception e) {
        throw new ApplicationRuntimeException("Error sending SFTP. " + e.getMessage());
    } finally {
        standardFileSystemManager.close();
    }
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.MapPersistenceBackendFactoryTest.java

@After
public void tearDown() {
    PersistenceBackendFactoryRegistry.getFactories().clear();
    if (testFolder != null) {
        try {/*w w w.  j  a v a 2 s  .co  m*/
            FileUtils.forceDelete(testFolder);
        } catch (IOException e) {

        }
        testFolder = null;
        testFile = null;
    }
}

From source file:com.hs.mail.imap.processor.AppendProcessor.java

private void forceDelete(File file) {
    try {/*from  w  w w .j a  va2 s  . com*/
        FileUtils.forceDelete(file);
    } catch (IOException e) {
        // Don't re-throw this exception
    }
}

From source file:com.linkedin.pinot.core.segment.store.SegmentDirectoryPathsTest.java

@Test
public void testFindMetadataFile() throws IOException {
    File tempDirectory = null;/*w w  w.j  av a2 s  . co m*/
    try {
        // setup temp dir, v3 subdir and create metadata.properties in both
        tempDirectory = new File(SegmentDirectoryPaths.class.toString());
        tempDirectory.deleteOnExit();
        FileUtils.forceMkdir(tempDirectory);
        File v3Dir = new File(tempDirectory, "v3");
        FileUtils.forceMkdir(v3Dir);
        File metaFile = new File(tempDirectory, V1Constants.MetadataKeys.METADATA_FILE_NAME);
        try (FileOutputStream outputStream = new FileOutputStream(metaFile)) {
            outputStream.write(10);
        }
        File v3MetaFile = new File(v3Dir, V1Constants.MetadataKeys.METADATA_FILE_NAME);
        FileUtils.copyFile(metaFile, v3MetaFile);

        {
            File testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), metaFile.toString());

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v1);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), metaFile.toString());

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v3);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), v3MetaFile.toString());
        }
        {
            // drop v1 metadata file
            FileUtils.forceDelete(metaFile);
            File testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), v3MetaFile.toString());

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v1);
            Assert.assertNull(testMetaFile);

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v3);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), v3MetaFile.toString());
        }
        {
            // drop v3 metadata file
            FileUtils.forceDelete(v3MetaFile);
            File testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory);
            Assert.assertNull(testMetaFile);

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v1);
            Assert.assertNull(testMetaFile);

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v3);
            Assert.assertNull(testMetaFile);
        }
    } finally {
        if (tempDirectory != null) {
            FileUtils.deleteQuietly(tempDirectory);
        }
    }
}

From source file:backtype.storm.utils.VersionedStore.java

public void deleteVersion(long version) throws IOException {
    File versionFile = new File(versionPath(version));
    File tokenFile = new File(tokenPath(version));

    if (tokenFile.exists()) {
        FileUtils.forceDelete(tokenFile);
    }/*from  w w w.  ja  v  a2  s.co m*/

    if (versionFile.exists()) {
        FileUtils.forceDelete(versionFile);
    }
}

From source file:io.druid.data.input.impl.prefetch.PrefetchableTextFilesFirehoseFactoryTest.java

@AfterClass
public static void teardown() throws IOException {
    FileUtils.forceDelete(TEST_DIR);
    for (File dir : FIREHOSE_TMP_DIRS) {
        FileUtils.forceDelete(dir);//from ww  w .j a  v a 2  s  .c o  m
    }
}

From source file:com.willwinder.universalgcodesender.utils.GcodeStreamTest.java

/**
 * Writes 1,000,000 rows to a file then reads it back out.
 *///from   w  w  w . ja v  a2s . com
@Test
public void testGcodeStreamReadWrite() throws FileNotFoundException, IOException {
    int rows = 1000000;
    File f = new File(tempDir, "gcodeFile");
    try {
        try (GcodeStreamWriter gsw = new GcodeStreamWriter(f)) {
            for (int i = 0; i < rows; i++) {
                gsw.addLine("Line " + i + " before", "Line " + i + " after", null, i);
            }
        }

        try (GcodeStreamReader gsr = new GcodeStreamReader(f)) {
            Assert.assertEquals(rows, gsr.getNumRows());

            int count = 0;
            while (gsr.getNumRowsRemaining() > 0) {
                GcodeCommand gc = gsr.getNextCommand();
                Assert.assertEquals("Line " + count + " after", gc.getCommandString());
                Assert.assertEquals("", gc.getComment());
                Assert.assertEquals(count, gc.getCommandNumber());
                count++;
                Assert.assertEquals(rows - count, gsr.getNumRowsRemaining());
            }

            Assert.assertEquals(rows, count);
        }
    } finally {
        FileUtils.forceDelete(f);
    }
}