List of usage examples for org.apache.commons.io FileUtils forceDelete
public static void forceDelete(File file) throws IOException
From source file:gov.va.vinci.leo.descriptors.LeoAEDescriptorTest.java
@Test public void testToXmlWithName() throws Exception { LeoAEDescriptor fd = new LeoAEDescriptor("desc.gov.va.vinci.leo.ae.TokenizerAggregateDescriptor", true); String name = fd.getName();/* w w w. ja v a 2s .c om*/ File xmlPath = new File(rootDirectory + "src/test/resources/xml-generated-test"); xmlPath.mkdir(); fd.setDescriptorLocator(xmlPath.toURI()); fd.toXML(name); assertTrue(xmlPath.listFiles().length == 3); FileUtils.forceDelete(xmlPath); }
From source file:com.constellio.sdk.tests.selenium.adapters.constellio.ConstellioWebDriver.java
private void createSnapshotFolderIfRequired() { if (firstBefore) { snapshotFolder = new File(foldersLocator.getSDKProject(), "snapshots"); if (snapshotFolder.exists()) { File[] files = snapshotFolder.listFiles(); if (files != null) { for (File file : files) { try { FileUtils.forceDelete(file); } catch (IOException e) { throw new RuntimeException(e); }//w w w. ja va 2 s . com } } } snapshotFolder.mkdirs(); firstBefore = false; } }
From source file:com.adaltas.flume.serialization.TestJSONEventSerializer.java
@Test public void testJson() throws FileNotFoundException, IOException { Map<String, String> headers = new HashMap<String, String>(); headers.put("header1", "value1"); headers.put("header2", "value2"); OutputStream out = new FileOutputStream(testFile); Context context = new Context(); // context.put("body", "body"); EventSerializer serializer = EventSerializerFactory .getInstance("com.adaltas.flume.serialization.JSONEventSerializer$Builder", context, out); serializer.afterCreate();//www . j a v a2 s.c om serializer.write(EventBuilder.withBody("event 1", Charsets.UTF_8, headers)); serializer.write(EventBuilder.withBody("event 2", Charsets.UTF_8, headers)); serializer.write(EventBuilder.withBody("event 3", Charsets.UTF_8, headers)); serializer.flush(); serializer.beforeClose(); out.flush(); out.close(); BufferedReader reader = new BufferedReader(new FileReader(testFile)); Assert.assertEquals("{\"body\":\"event 1\",\"header2\":\"value2\",\"header1\":\"value1\"}", reader.readLine()); Assert.assertEquals("{\"body\":\"event 2\",\"header2\":\"value2\",\"header1\":\"value1\"}", reader.readLine()); Assert.assertEquals("{\"body\":\"event 3\",\"header2\":\"value2\",\"header1\":\"value1\"}", reader.readLine()); Assert.assertNull(reader.readLine()); reader.close(); FileUtils.forceDelete(testFile); }
From source file:hoot.services.controllers.ingest.BasemapResourceTest.java
@Test @Category(UnitTest.class) public void TestgetBasemapList() throws Exception { BasemapResource mapRes = new BasemapResource(); File f = new File(mapRes._tileServerPath + "/BASEMAP/TestMap"); FileUtils.forceMkdir(f);//w ww . j a v a2 s .c o m JSONObject cont = new JSONObject(); cont.put("jobid", "123-456-789"); cont.put("path", "/projects/hoot/ingest/processed/BASEMAP/TestMap"); File file = new File(mapRes._ingestStagingPath + "/BASEMAP/TestMap.enabled"); FileUtils.writeStringToFile(file, cont.toJSONString()); File f2 = new File(mapRes._tileServerPath + "/BASEMAP/TestMap2"); FileUtils.forceMkdir(f2); File file2 = new File(mapRes._ingestStagingPath + "/BASEMAP/TestMap2.enabled"); FileUtils.writeStringToFile(file2, cont.toJSONString()); JSONArray res = mapRes._getBasemapList(); boolean found = false; for (Object oMap : res) { JSONObject map = (JSONObject) oMap; if (map.get("name").toString().equals("TestMap")) { found = true; break; } } org.junit.Assert.assertTrue(found); FileUtils.forceDelete(f); FileUtils.forceDelete(f2); }
From source file:com.yahoo.sshd.authentication.file.TestPKUpdating.java
private TestContext setup() throws IOException, InterruptedException { TestContext testContext = new TestContext(); // first build dirs. if (homeDir.exists()) { FileUtils.forceDelete(homeDir); }/*from ww w . j a va2s . c o m*/ FileUtils.forceMkdir(homeDir); // build user directories. User[] dirs = new User[normalUsers.length + notUsers.length]; System.arraycopy(normalUsers, 0, dirs, 0, normalUsers.length); System.arraycopy(notUsers, 0, dirs, normalUsers.length, notUsers.length); buildSshDirs(homeDir, dirs); // this point everyone in users has a public key, so we can load it, and // check for them. CountDownLatch waiter = new CountDownLatch(1); testContext.publickeyAuthenticator = new HomeDirectoryScanningPKAuthenticator(waiter, homeDir, Arrays.asList(new Path[] { new File(homeDir, "y").toPath() })); testContext.publickeyAuthenticator.start(); waiter.await(); checkExist(testContext, normalUsers); checkDoesntExist(testContext, notUsers); return testContext; }
From source file:com.google.gct.idea.appengine.synchronization.SampleSyncTask.java
private Git cloneGithubRepo() { File localRepoDirectory = new File(LOCAL_REPO_PATH); if (localRepoDirectory.exists()) { try {// www.ja va 2 s .co m FileUtils.forceDelete(localRepoDirectory); } catch (IOException e) { LOG.error("Error deleting " + LOCAL_REPO_PATH, e); } } try { Git localGitRepo = Git.cloneRepository().setURI(SAMPLE_LINK).setDirectory(new File(LOCAL_REPO_PATH)) .call(); return localGitRepo; } catch (GitAPIException e) { LOG.error("Error cloning github sample repository: " + SAMPLE_LINK, e); } return null; }
From source file:com.qualinsight.mojo.cobertura.core.AbstractCleaningReportMojo.java
private void cleanupFileSystem(final File classesDirectory, final File backupClassesDirectory, final File baseDataFile, final File destinationDataFile) throws MojoExecutionException { getLog().debug("Cleaning up file system after Cobertura report generation"); try {//from w ww .java 2s . c o m FileUtils.forceDelete(classesDirectory); FileUtils.moveDirectory(backupClassesDirectory, classesDirectory); FileUtils.moveFile(baseDataFile, destinationDataFile); } catch (final IOException e) { final String message = "An error occurred during file system cleanup: "; getLog().error(message, e); throw new MojoExecutionException(message, e); } }
From source file:cd.education.data.collector.android.external.ExternalDataReaderImpl.java
@Override public void doImport(Map<String, File> externalDataMap) { for (Map.Entry<String, File> stringFileEntry : externalDataMap.entrySet()) { String dataSetName = stringFileEntry.getKey(); File dataSetFile = stringFileEntry.getValue(); if (dataSetFile.exists()) { File dbFile = new File(dataSetFile.getParentFile().getAbsolutePath(), dataSetName + ".db"); if (dbFile.exists()) { // this means the someone updated the csv file, so we need to reload it boolean deleted = dbFile.delete(); if (!deleted) { Log.e(ExternalDataUtil.LOGGER_NAME, dataSetFile.getName() + " has changed but we could not delete the previous DB at " + dbFile.getAbsolutePath()); continue; }//from ww w. java 2 s . c o m } ExternalSQLiteOpenHelper externalSQLiteOpenHelper = new ExternalSQLiteOpenHelper(dbFile); externalSQLiteOpenHelper.importFromCSV(dataSetFile, this, formLoaderTask); if (formLoaderTask.isCancelled()) { Log.w(ExternalDataUtil.LOGGER_NAME, "The import was cancelled, so we need to rollback."); // we need to drop the database file since it might be partially populated. It will be re-created next time. Log.w(ExternalDataUtil.LOGGER_NAME, "Closing database to be deleted " + dbFile); // then close the database SQLiteDatabase db = externalSQLiteOpenHelper.getReadableDatabase(); db.close(); // the physically delete the db. try { FileUtils.forceDelete(dbFile); Log.w(ExternalDataUtil.LOGGER_NAME, "Deleted " + dbFile.getName()); } catch (IOException e) { Log.e(ExternalDataUtil.LOGGER_NAME, e.getMessage(), e); } // then just exit and do not process any other CSVs. return; } else { // rename the dataSetFile into "dataSetFile.csv.imported" in order not to be loaded again File importedFile = new File(dataSetFile.getParentFile(), dataSetFile.getName() + ".imported"); boolean renamed = dataSetFile.renameTo(importedFile); if (!renamed) { Log.e(ExternalDataUtil.LOGGER_NAME, dataSetFile.getName() + " could not be renamed to be archived. It will be re-imported again! :("); } else { Log.e(ExternalDataUtil.LOGGER_NAME, dataSetFile.getName() + " was renamed to " + importedFile.getName()); } } } } }
From source file:ch.sbb.releasetrain.git.GITAccessor.java
public void reset() { writeModel();//from ww w . j a v a 2 s .c o m repo = client.gitRepo(model.getConfigUrl(), model.getConfigBranch(), model.getConfigUser(), model.getEncPassword()); err = ""; read = false; write = false; repo.reset(); try { repo.cloneOrPull(); read = true; File dir = repo.directory(); FileUtils.writeStringToFile(new File(dir, "test.txt"), new Date().toString()); repo.addCommitPush(); write = true; FileUtils.forceDelete(new File(dir, "test.txt")); repo.addCommitPush(); } catch (Exception e) { log.error(e.getMessage(), e); err = e.getMessage(); } }
From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePublicKeyDataProvider.java
@Test public void testGetEncryptedPublicKeyData01() throws IOException { final String fileName = "testGetEncryptedPublicKeyData01.key"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file); FilePublicKeyDataProvider provider = new FilePublicKeyDataProvider(file); try {/*from w w w .jav a 2s . co m*/ provider.getEncryptedPublicKeyData(); fail("Expected exception KeyNotFoundException."); } catch (KeyNotFoundException e) { assertNull("The cause should be null.", e.getCause()); } }