List of usage examples for org.apache.commons.io FileUtils forceDelete
public static void forceDelete(File file) throws IOException
From source file:com.zuehlke.sbdfx.dataimport.SourceFilesFetcher.java
private void downloadLink(final WebLink webLink) throws IOException { final String urlString = webLink.getURLString(); OutputStream output = null;/*from www. j av a 2 s . c o m*/ InputStream input = null; try { if (isLinkToDownload(urlString)) { final File targetFile = new File(targetFolder, urlString); if (targetFile.exists()) { FileUtils.forceDelete(targetFile); } final File tempFile = new File(targetFolder, "currentDownload"); if (tempFile.exists()) { FileUtils.forceDelete(tempFile); } LOGGER.info("Downloading {} to {}", urlString, targetFile.getAbsolutePath()); URL srcUrl = new URL(new URL(SOURCE_FOLDER), urlString); input = srcUrl.openStream(); output = new FileOutputStream(tempFile); IOUtils.copyLarge(input, output); output.close(); FileUtils.moveFile(tempFile, targetFile); } else { LOGGER.info("NOT Downloading {}", urlString); } } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(input); } }
From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePublicKeyDataProvider.java
@Test public void testKeyFile02() throws IOException { final String fileName = "testKeyFile02.key"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file); FilePublicKeyDataProvider provider = new FilePublicKeyDataProvider(file); assertNotNull("The key file should not be null.", provider.getPublicKeyFile()); assertNotSame("The objects should not be the same.", file, provider.getPublicKeyFile()); assertEquals("The key file is not correct.", file.getAbsoluteFile(), provider.getPublicKeyFile()); assertFalse("The paths should not be the same.", fileName.equals(provider.getPublicKeyFile().getPath())); assertTrue("The paths should end the same.", provider.getPublicKeyFile().getPath().endsWith(fileName)); }
From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePrivateKeyDataProvider.java
@Test public void testKeyFile02() throws IOException { final String fileName = "testKeyFile02.key"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file); FilePrivateKeyDataProvider provider = new FilePrivateKeyDataProvider(file); assertNotNull("The key file should not be null.", provider.getPrivateKeyFile()); assertNotSame("The objects should not be the same.", file, provider.getPrivateKeyFile()); assertEquals("The key file is not correct.", file.getAbsoluteFile(), provider.getPrivateKeyFile()); assertFalse("The paths should not be the same.", fileName.equals(provider.getPrivateKeyFile().getPath())); assertTrue("The paths should end the same.", provider.getPrivateKeyFile().getPath().endsWith(fileName)); }
From source file:com.gemstone.gemfire.management.internal.configuration.ZipUtilsJUnitTest.java
private void forceDelete(File f) throws Exception { try {//from w ww . j av a2 s . c o m FileUtils.forceDelete(f); } catch (FileNotFoundException e) { // ignored } }
From source file:io.druid.data.input.impl.prefetch.PrefetchableTextFilesFirehoseFactoryTest.java
@BeforeClass public static void setup() throws IOException { TEST_DIR = File.createTempFile(PrefetchableTextFilesFirehoseFactoryTest.class.getSimpleName(), "testDir"); FileUtils.forceDelete(TEST_DIR); FileUtils.forceMkdir(TEST_DIR);/* w ww .j a v a2 s . com*/ for (int i = 0; i < 100; i++) { try (CountingOutputStream cos = new CountingOutputStream( Files.newOutputStream(new File(TEST_DIR, "test_" + i).toPath())); Writer writer = new BufferedWriter(new OutputStreamWriter(cos, StandardCharsets.UTF_8))) { for (int j = 0; j < 100; j++) { final String a = StringUtils.format("%d,%03d,%03d\n", (20171220 + i), i, j); writer.write(a); } writer.flush(); // Every file size must be same if (FILE_SIZE == -1) { FILE_SIZE = cos.getCount(); } else { Assert.assertEquals(FILE_SIZE, cos.getCount()); } } } }
From source file:com.martinwunderlich.nlp.arg.aifdb.test.ArgMapTest.java
@org.junit.Test public void testMapCountsA() { List<AIFdbArgumentMap> araucariaList = AIFdbArgumentMapFactory .buildArgumentMapListFromNodesetJsonFiles(araucariaPath); assertEquals("The number of argument maps in the araucaria list is incorrect", araucariaList.size(), 661); try {//from w w w . j ava 2 s.c o m String filePath = "src/test/resources/araucaria/outfile.txt"; File outFile = new File(filePath); if (outFile.exists()) FileUtils.forceDelete(outFile); AIFdbArgumentMapUtil.printNodesToFile(araucariaList, NODE_TYPES.I, "src/test/resources/araucaria/outfile.txt"); } catch (IOException e) { fail("Error while trying to write map list to file: " + e.getLocalizedMessage()); } }
From source file:com.mirth.connect.util.messagewriter.MessageWriterArchive.java
/** * Ends message writing and moves the written folders/files into the archive file. *//*from w ww . j a v a 2s .c o m*/ @Override public void finishWrite() throws MessageWriterException { fileWriter.close(); if (messagesWritten) { try { File tempFile = new File( archiveFile.getParent() + IOUtils.DIR_SEPARATOR + "." + archiveFile.getName()); try { FileUtils.forceDelete(tempFile); } catch (FileNotFoundException e) { } ArchiveUtils.createArchive(rootFolder, tempFile, archiver, compressor); try { FileUtils.forceDelete(archiveFile); } catch (FileNotFoundException e) { } FileUtils.moveFile(tempFile, archiveFile); } catch (Exception e) { throw new MessageWriterException(e); } finally { FileUtils.deleteQuietly(rootFolder); } } }
From source file:gov.nih.nci.sdk.example.generator.WebServiceGenerator.java
protected void preProcess() { if (getScriptContext().getMemory().get("preProcess") == null) { // Delete generated folder try {/* ww w.j a v a 2 s . co m*/ String generatedPath = GeneratorUtil.getServicePath(getScriptContext()); if (new File(generatedPath).exists() == true) { FileUtils.forceDelete(new File(generatedPath)); } } catch (Throwable t) { getScriptContext().logError(t); // TODO Auto-generated catch block t.printStackTrace(); } try { String classesPath = GeneratorUtil.getClassesPath(getScriptContext()); if (new File(classesPath).exists() == true) { FileUtils.forceDelete(new File(classesPath)); } } catch (Throwable t) { getScriptContext().logError(t); // TODO Auto-generated catch block t.printStackTrace(); } getScriptContext().getMemory().put("preProcess", ""); } }
From source file:com.thoughtworks.go.agent.AgentPluginsInitializer.java
@Override public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { try {// w w w .j a v a 2 s. co m File pluginsFolder = new File(systemEnvironment.get(SystemEnvironment.AGENT_PLUGINS_PATH)); if (pluginsFolder.exists()) { FileUtils.forceDelete(pluginsFolder); } zipUtil.unzip(DownloadableFile.AGENT_PLUGINS.getLocalFile(), pluginsFolder); defaultPluginJarLocationMonitor.initialize(); pluginManager.startInfrastructure(false); } catch (IOException e) { LOG.warn("could not extract plugin zip", e); } catch (RuntimeException e) { LOG.warn("error while initializing agent plugins", e); } }
From source file:com.datatorrent.stram.cli.DTCliTest.java
@AfterClass public static void finished() { try {/*ww w . j a va2 s .c o m*/ env.put("HOME", userHome); setEnv(env); StramTestSupport.removeAppPackageFile(); FileUtils.forceDelete(configFile); testFolder.delete(); } catch (Exception e) { throw new RuntimeException(e); } }