List of usage examples for org.apache.commons.io FileUtils forceDelete
public static void forceDelete(File file) throws IOException
From source file:com.ariht.maven.plugins.config.ConfigProcessorMojo.java
private void deleteOutputDirectory() throws IOException { final File outputDir = new File(outputBasePath); if (outputDir.exists()) { getLog().debug("Deleting : " + outputDir); FileUtils.forceDelete(outputDir); }//from w w w . j a va 2s .c om }
From source file:ddf.catalog.backup.CatalogBackupPlugin.java
private void deleteFile(Metacard metacard) throws IOException { File metacardToDelete = getFile(metacard.getId(), ""); FileUtils.forceDelete(metacardToDelete); }
From source file:hoot.services.controllers.info.ReportsResourceTest.java
@Test @Category(UnitTest.class) public void testDeleteReport() throws Exception { String storePath = _rps._homeFolder + "/" + _rps._rptStorePath; File f = new File(storePath); File fWks = new File(storePath + "/123_test_del"); if (fWks.exists()) { FileUtils.forceDelete(fWks); }//ww w . ja v a 2 s .co m FileUtils.forceMkdir(f); FileUtils.forceMkdir(fWks); String currTime = "" + System.currentTimeMillis(); JSONObject metaData = new JSONObject(); metaData.put("name", "Test Report1"); metaData.put("description", "This is test report 1"); metaData.put("created", currTime); metaData.put("reportpath", _rps._homeFolder + "/test-files/test_report1.pdf"); File meta = new File(storePath + "/123_test_del/meta.data"); FileUtils.write(meta, metaData.toJSONString()); boolean isDel = _rps._deleteReport("123_test_del_not_exist"); assertFalse(isDel); isDel = _rps._deleteReport("123_test_del"); assertTrue(isDel); }
From source file:de.interactive_instruments.ShapeChange.Target.Metadata.ApplicationSchemaMetadata.java
@Override public void initialise(PackageInfo p, Model m, Options o, ShapeChangeResult r, boolean diagOnly) throws ShapeChangeAbortException { schemaPi = p;//from w ww .j ava2 s . c om schemaTargetNamespace = p.targetNamespace(); model = m; options = o; result = r; diagnosticsOnly = diagOnly; result.addDebug(this, 1, schemaPi.name()); if (!initialised) { initialised = true; outputDirectory = options.parameter(this.getClass().getName(), "outputDirectory"); if (outputDirectory == null) outputDirectory = options.parameter("outputDirectory"); if (outputDirectory == null) outputDirectory = options.parameter("."); outputFilename = "schema_metadata.xml"; // 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) { for (ProcessMapEntry pme : mapEntries) { 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 // ====================================== // nothing to do at present // ====================================== // 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(NS, "ApplicationSchemaMetadata"); document.appendChild(root); addAttribute(root, "xmlns", NS); hook = document.createComment("Created by ShapeChange - http://shapechange.net/"); root.appendChild(hook); } // create elements documenting the application schema Element e_name = document.createElement("name"); e_name.setTextContent(schemaPi.name()); Element e_tns = document.createElement("targetNamespace"); e_tns.setTextContent(schemaPi.targetNamespace()); Element e_as = document.createElement("ApplicationSchema"); e_as.appendChild(e_name); e_as.appendChild(e_tns); Element e_schema = document.createElement("schema"); e_schema.appendChild(e_as); root.appendChild(e_schema); /* * Now compute relevant metadata. */ processMetadata(e_as); }
From source file:com.netsteadfast.greenstep.util.UploadSupportUtils.java
public static void cleanTempUpload(String system) throws ServiceException, Exception { logger.info("clean upload(" + system + ") temp begin..."); sysUploadService.deleteTmpContent(system); Map<String, Object> params = new HashMap<String, Object>(); params.put("system", system); params.put("type", UploadTypes.IS_TEMP); params.put("isFile", YesNo.YES); List<TbSysUpload> searchList = sysUploadService.findListByParams(params); for (int i = 0; searchList != null && i < searchList.size(); i++) { TbSysUpload entity = searchList.get(i); String dir = getUploadFileDir(entity.getSystem(), entity.getSubDir(), entity.getType()); String fileFullPath = dir + "/" + entity.getFileName(); File file = new File(fileFullPath); if (!file.exists()) { file = null;//from w w w. j a v a 2 s.c o m continue; } try { logger.warn("delete : " + file.getPath()); FileUtils.forceDelete(file); sysUploadService.delete(entity); } catch (IOException e) { e.printStackTrace(); } } logger.info("end..."); }
From source file:com.mindquarry.desktop.workspace.conflict.DeleteWithModificationConflict.java
public void beforeUpdate() throws ClientException, IOException { // NOTE: here we could implement a fast-path avoiding the download // of the new files by simply deleting the folder on the server // before we run the update // if (action == Action.DELETE) { // nothing to do here, we have to wait for the update and delete // the folder again (svn will recreate it due to the remote mods) // }/*www . j ava 2 s . c o m*/ if (action == Action.REVERTDELETE) { if (localDelete) { // revert local delete log.info("beforeUpdate (localDelete), reverting " + status.getPath()); client.revert(status.getPath(), true); } else { // make a local copy of the file/dir File source = new File(status.getPath()); // temp file prefix is required to be at least 3 chars long, so add another prefix: String tmpPrefix = TEMP_FILE_PREFIX + source.getName(); if (source.isFile()) { tempCopy = File.createTempFile(tmpPrefix, null, source.getParentFile()); FileUtils.copyFile(source, tempCopy); } else { tempCopy = createTempDir(tmpPrefix, null, source.getParentFile()); FileUtils.copyDirectory(source, tempCopy); } // remove .svn directories from copy (if there are any) removeDotSVNDirectories(tempCopy.getPath()); // revert all local changes to file/dir log.info("beforeUpdate, reverting " + status.getPath()); client.revert(status.getPath(), true); // TODO: really delete folder before svn copy // We will do a svn copy of an old version into this folder // after the update. To do this, the folder must not exist // anymore locally, and should not be seen as 'missing'. // Otherwise svn is forced to overwrite some existing, versioned // folder, which fails with errors like: // - 'Revision 1 doesn't match existing revision 2' // if the folder is removed ('missing') // - 'path refers to directory or read access is denied' // if the folder exists, but is 'unversioned' // it has to be in normal state, so that during the update it // gets deleted through the remote changes - the deletion will // then be reverted through the svn copy from the last version // before the deletion // TODO: this is wrong, only delete unversioned files // Delete complete file/dir as the update operation will leave // unversioned copies of files that were locally modified. FileUtils.forceDelete(source); } } }
From source file:net.nicholaswilliams.java.licensing.encryption.TestKeyFileUtilities.java
@Test public void testPublicKeyEncryption02() throws Throwable { File file = new File("testPublicKeyEncryption02.key"); if (file.exists()) FileUtils.forceDelete(file); PublicKey publicKey = KeyPairGenerator.getInstance(KeyFileUtilities.keyAlgorithm).generateKeyPair() .getPublic();/*from ww w.j a v a 2 s .c om*/ PublicKey otherKey = KeyPairGenerator.getInstance(KeyFileUtilities.keyAlgorithm).generateKeyPair() .getPublic(); assertFalse("The keys should not be equal (1).", otherKey.equals(publicKey)); KeyFileUtilities.writeEncryptedPublicKey(publicKey, file, "yourTestPassword02".toCharArray()); PublicKey publicKey2 = KeyFileUtilities.readEncryptedPublicKey(file, "yourTestPassword02".toCharArray()); assertNotNull("The key should not be null.", publicKey2); assertFalse("The objects should not be the same.", publicKey == publicKey2); assertEquals("The keys should be the same.", publicKey, publicKey2); assertFalse("The keys should not be equal (2).", otherKey.equals(publicKey2)); FileUtils.forceDelete(file); }
From source file:massbank.BatchJobWorker.java
public void run() { File attacheDir = null;/* w ww . j a v a2 s . c om*/ try { GetConfig conf = new GetConfig(BatchService.BASE_URL); this.serverUrl = conf.getServerUrl(); String tempDir = System.getProperty("java.io.tmpdir"); File temp = File.createTempFile("batchRes", ".txt"); String queryFilePath = tempDir + "/" + this.fileName; String resultFilePath = tempDir + "/" + temp.getName(); // ** open temporary file File f1 = new File(queryFilePath); File f2 = new File(resultFilePath); BufferedReader in = new BufferedReader(new FileReader(f1)); PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(f2))); String line; name = ""; peak = ""; sendLen = 0; writer.println(mailAddress); sendLen += mailAddress.length() + 1; String year = this.timeStamp.substring(0, 4); String month = this.timeStamp.substring(4, 6); String day = this.timeStamp.substring(6, 8); String hour = this.timeStamp.substring(8, 10); String minute = this.timeStamp.substring(10, 12); String second = this.timeStamp.substring(12, 14); String time = year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second + " JST"; writer.println(time); sendLen += time.length() + 1; writer.println(); sendLen++; name = "(none)"; int flag = 0; while ((line = in.readLine()) != null) { line = line.trim(); if (line.startsWith("//")) { continue; } else if (line.matches("^Name:.*")) { name = line; name = line.replaceFirst("^Name: *", "").replaceFirst("^ *$", ""); peak = ""; flag = 1; } else if (line.matches(".*:.*")) { } else if (line.matches("^$")) { if (flag == 0) { continue; } flag = 0; doSearch(writer); if (sendLen >= LIMIT) { break; } } else { peak += " " + line; } // Xbh?I if (isTerminated) { break; } } in.close(); if (flag == 1 && sendLen < LIMIT) { doSearch(writer); } writer.flush(); writer.close(); if (isTerminated) { f2.delete(); return; } // ??[?M??? AdminCommon admin = new AdminCommon(BatchService.BASE_URL, BatchService.REAL_PATH); SendMailInfo info = new SendMailInfo(admin.getMailSmtp(), admin.getMailFrom(), this.mailAddress); info.setFromName(admin.getMailName()); info.setSubject("MassBank Batch Service Results"); info.setContents("Dear Users,\n\nThank you for using MassBank Batch Service.\n" + "\n" + "The results for your request dated '" + time + "' are attached to this e-mail.\n" + "\n" + "--\n" + "MassBank.jp - High Resolution Mass Spectral Database\n" + " URL: http://www.massbank.jp/\n" + " E-mail: massbank@iab.keio.ac.jp"); // Ytt@C??fBNg attacheDir = new File(tempDir + "/batch_" + RandomStringUtils.randomAlphanumeric(9)); while (attacheDir.exists()) { attacheDir = new File(tempDir + "/batch_" + RandomStringUtils.randomAlphanumeric(9)); } attacheDir.mkdir(); // Ytt@C???ieLXg`?j File textFile = new File(attacheDir.getPath() + "/MassBankResults.txt"); textFile.createNewFile(); createTextFile(time, f2, textFile); // Ytt@C???iHTML`?j File htmlFile = new File(attacheDir.getPath() + "/MassBankResults.html"); htmlFile.createNewFile(); createHtmlFile(time, f2, htmlFile); info.setFiles(new File[] { textFile, htmlFile }); // ??[?M SendMail.send(info); // WuGg?? BatchJobManager job = new BatchJobManager(); job.deleteEntry(this.sessionId, this.timeStamp); // ** delete temporary file f1.delete(); f2.delete(); } catch (Exception e) { e.printStackTrace(); } finally { if (attacheDir != null && attacheDir.isDirectory()) { try { FileUtils.forceDelete(attacheDir); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:fr.gael.dhus.datastore.processing.impl.ProcessProductImages.java
@Override public void removeProcessing(Product product) { File th_container = null;//from w ww . java2 s . c om File ql_container = null; if (product.getThumbnailFlag()) { th_container = new File(product.getThumbnailPath()); if (IncomingManager.INCOMING_PRODUCT_DIR.equals(th_container.getParentFile().getName())) th_container = th_container.getParentFile(); if (HierarchicalDirectoryBuilder.DHUS_ENTRY_NAME.equals(th_container.getParentFile().getName())) th_container = th_container.getParentFile(); } if (product.getQuicklookFlag()) { ql_container = new File(product.getQuicklookPath()); if (IncomingManager.INCOMING_PRODUCT_DIR.equals(ql_container.getParentFile().getName())) ql_container = ql_container.getParentFile(); if (HierarchicalDirectoryBuilder.DHUS_ENTRY_NAME.equals(ql_container.getParentFile().getName())) ql_container = ql_container.getParentFile(); } try { if (th_container != null) FileUtils.forceDelete(th_container); if (ql_container != null) FileUtils.forceDelete(ql_container); } catch (Exception e) { // may happen if th_container=ql_container } }
From source file:eu.udig.catalog.jgrass.operations.RemoveMapAction.java
/** * Given the mapsetpath and the mapname, the map is removed with all its accessor files * /* w w w . ja va 2 s . co m*/ * @param mapsetPath * @param mapName * @throws IOException */ public void removeGrassRasterMap(String mapsetPath, String mapName) throws IOException { // list of files to remove String mappaths[] = JGrassCatalogUtilities.filesOfRasterMap(mapsetPath, mapName); // first delete the list above, which are just files for (int j = 0; j < mappaths.length; j++) { File filetoremove = new File(mappaths[j]); if (filetoremove.exists()) { FileUtils.forceDelete(filetoremove); } } }