List of usage examples for org.apache.commons.io FileUtils forceDelete
public static void forceDelete(File file) throws IOException
From source file:de.awtools.xml.XSLTransformer.java
/** * Existiert das Target-File bereits, so wird dieses gelscht und dann * neu angelegt./*from ww w . j a v a 2s . c o m*/ * * @param targetFile Target-Datei. * @throws IOException Die Datei konnte nicht gelscht oder angelegt werden. */ private void cleanTargetFile(final File targetFile) throws IOException { if (targetFile.exists()) { FileUtils.forceDelete(targetFile); } if (!targetFile.createNewFile()) { log.debug("Can not create target file '" + getTarget() + "'!"); } }
From source file:au.org.ala.names.search.ALANameIndexer.java
/** * Creates an index writer in the specified directory. It will create/recreate * the target directory// w w w. ja v a 2s. c o m * * @param directory * @param analyzer * @return * @throws Exception */ protected IndexWriter createIndexWriter(File directory, Analyzer analyzer, boolean replace) throws Exception { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_34, analyzer); if (replace) conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE); else conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); if (directory.exists() && replace) { FileUtils.forceDelete(directory); } FileUtils.forceMkdir(directory); IndexWriter iw = new IndexWriter(FSDirectory.open(directory), conf); return iw; }
From source file:ddf.security.pdp.realm.xacml.processor.XacmlClientTest.java
@Test public void testWrapperpoliciesdirectorydoesnotexist() throws PdpException, IOException { LOGGER.debug("\n\n\n##### testXACMLWrapper_policies_directory_does_not_exist"); // Perform Test on new directory // Expect directory to be created new XacmlClient(TEST_CREATION_DIR, new XmlParser()); // Delete the directory that was just created FileUtils.forceDelete(new File(TEST_CREATION_DIR)); }
From source file:ddf.security.pdp.realm.xacml.processor.BalanaClientTest.java
@Test public void testBalanaWrapperpoliciesdirectorydoesnotexist() throws PdpException, IOException { LOGGER.debug("\n\n\n##### testBalanaWrapper_policies_directory_does_not_exist"); // Perform Test on new directory // Expect directory to be created new BalanaClient(TEST_CREATION_DIR, new XmlParser()); // Delete the directory that was just created FileUtils.forceDelete(new File(TEST_CREATION_DIR)); }
From source file:com.docd.purefm.utils.PFMFileUtils.java
public static void forceDelete(@NonNull final GenericFile file, final boolean useCommandLine) throws IOException { if (useCommandLine) { if (!file.exists()) { throw new FileNotFoundException("File does not exist: " + file); }/* w w w. ja v a 2s . co m*/ final boolean result = CommandLine.execute(new CommandRemove(file.toFile())); if (!result) { throw new IOException("Removing failed"); } } else { FileUtils.forceDelete(file.toFile()); } }
From source file:co.kuali.coeus.sys.impl.persistence.SchemaSpyFilter.java
private void deleteSchemaSpyContent() { if (Files.exists(getSchemaSpyPath())) { try {// ww w . j a va2 s . c o m FileUtils.forceDelete(getSchemaSpyPath().toFile()); } catch (IOException e) { LOG.warn(e.getMessage(), e); } } }
From source file:eu.earthobservatory.org.StrabonEndpoint.QueryBean.java
/** * Processes the request made from the HTML visual interface of Strabon Endpoint. * // w w w. j av a 2 s.c o m * @param request * @param response * @throws ServletException * @throws IOException */ private void processVIEWRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher; // check whether Update submit button was fired String reqFuncionality = (request.getParameter("submit") == null) ? "" : request.getParameter("submit"); if (reqFuncionality.equals("Update")) { // get the dispatcher for forwarding the rendering of the response dispatcher = request.getRequestDispatcher("/Update"); dispatcher.forward(request, response); } else { String query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); String format = request.getParameter("format"); String handle = request.getParameter("handle"); String maxLimit = request.getParameter("maxLimit"); // get stSPARQLQueryResultFormat from given format name TupleQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format); if (query == null || format == null || queryResultFormat == null) { dispatcher = request.getRequestDispatcher("query.jsp"); request.setAttribute(ERROR, PARAM_ERROR); dispatcher.forward(request, response); } else { query = strabonWrapper.addLimit(query, maxLimit); if ("download".equals(handle)) { // download as attachment ServletOutputStream out = response.getOutputStream(); response.setContentType(queryResultFormat.getDefaultMIMEType()); response.setHeader("Content-Disposition", "attachment; filename=results." + queryResultFormat.getDefaultFileExtension() + "; " + queryResultFormat.getCharset()); try { strabonWrapper.query(query, format, out); response.setStatus(HttpServletResponse.SC_OK); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.print(ResponseMessages.getXMLHeader()); out.print(ResponseMessages.getXMLException(e.getMessage())); out.print(ResponseMessages.getXMLFooter()); } out.flush(); } else if (("map".equals(handle) || "map_local".equals(handle) || "timemap".equals(handle)) && (queryResultFormat == stSPARQLQueryResultFormat.KML || queryResultFormat == stSPARQLQueryResultFormat.KMZ)) { // show map (only valid for KML/KMZ) // get dispatcher dispatcher = request.getRequestDispatcher("query.jsp"); // re-assign handle request.setAttribute("handle", handle); SecureRandom random = new SecureRandom(); String temp = new BigInteger(130, random).toString(32); // the temporary KML/KMZ file to create in the server String tempKMLFile = temp + "." + queryResultFormat.getDefaultFileExtension(); ; try { Date date = new Date(); // get the absolute path of the temporary directory if (!request.getParameter("handle").toString().contains("timemap")) { tempDirectory = appName + "-temp"; basePath = context.getRealPath("/") + "/../ROOT/" + tempDirectory + "/"; // fix the temporary directory for this web application FileUtils.forceMkdir(new File(basePath)); @SuppressWarnings("unchecked") Iterator<File> it = FileUtils.iterateFiles(new File(basePath), null, false); while (it.hasNext()) { File tbd = new File((it.next()).getAbsolutePath()); if (FileUtils.isFileOlder(new File(tbd.getAbsolutePath()), date.getTime())) { FileUtils.forceDelete(new File(tbd.getAbsolutePath())); } } } else { //timemap case tempDirectory = "js/timemap"; basePath = context.getRealPath("/") + tempDirectory + "/"; // fix the temporary directory for this web application } // fix the temporary directory for this web application // create temporary KML/KMZ file File file = new File(basePath + tempKMLFile); // if file does not exist, then create it if (!file.exists()) { file.createNewFile(); } try { // query and write the result in the temporary KML/KMZ file FileOutputStream fos = new FileOutputStream(basePath + tempKMLFile); strabonWrapper.query(query, format, fos); fos.close(); if (request.getParameter("handle").toString().contains("timemap")) { request.setAttribute("pathToKML", tempDirectory + "/" + tempKMLFile); } else { request.setAttribute("pathToKML", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/" + tempDirectory + "/" + tempKMLFile); } } catch (MalformedQueryException e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying. {}", e.getMessage()); request.setAttribute(ERROR, e.getMessage()); } catch (Exception e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); request.setAttribute(ERROR, e.getMessage()); } dispatcher.forward(request, response); } catch (IOException e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); } } else { // "plain" is assumed as the default dispatcher = request.getRequestDispatcher("query.jsp"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { strabonWrapper.query(query, format, bos); if (format.equals(Common.getHTMLFormat())) { request.setAttribute(RESPONSE, bos.toString()); } else if (format.equals(Format.PIECHART.toString()) || format.equals(Format.AREACHART.toString()) || format.equals(Format.COLUMNCHART.toString())) { request.setAttribute("format", "CHART"); request.setAttribute(RESPONSE, strabonWrapper.getgChartString()); } else { request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString())); } } catch (MalformedQueryException e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying. {}", e.getMessage()); request.setAttribute(ERROR, e.getMessage()); } catch (Exception e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); request.setAttribute(ERROR, e.getMessage()); } finally { dispatcher.forward(request, response); } } } } }
From source file:com.google.gdt.eclipse.designer.core.model.widgets.ClassLoaderTest.java
/** * Makes single {@link File} empty.//from ww w . j a v a 2s . c om */ private static void makeGwtJarEmpty(File file) throws IOException { // try delete try { FileUtils.forceDelete(file); } catch (Throwable e) { } // if not possible, make it empty IOUtils2.writeBytes(file, ArrayUtils.EMPTY_BYTE_ARRAY); }
From source file:com.wavemaker.tools.project.LocalStudioFileSystem.java
@Override public boolean deleteFile(Resource resource) { Assert.isInstanceOf(FileSystemResource.class, resource, "Expected a FileSystemResource"); FileSystemResource fileResource = (FileSystemResource) resource; if (fileResource.getFile().isDirectory()) { try {//from w ww . ja va2s . c o m FileUtils.forceDelete(fileResource.getFile()); return true; } catch (IOException ex) { throw new WMRuntimeException(ex); } } else { return fileResource.getFile().delete(); } }
From source file:edu.ur.file.db.FileSystemManager.java
/** * Delete a file from the file system.// w w w . j a v a2s. c o m * * @param file * @return true if the file is deleted from the file system. */ static boolean deleteFile(File file) { if (!file.exists()) { return true; } try { FileUtils.forceDelete(file); } catch (IOException io) { throw new RuntimeException("Could not delete file " + file.getAbsolutePath(), io); } return true; }