List of usage examples for org.apache.commons.io FileUtils cleanDirectory
public static void cleanDirectory(File directory) throws IOException
From source file:org.kalypso.model.wspm.tuhh.core.wspwin.WspWinExportGmlOperation.java
@Override public IStatus execute(final IProgressMonitor monitor) throws InvocationTargetException { try {/*from ww w . ja v a 2 s .c o m*/ final WspmWaterBody[] waters = m_data.getWaterBodies(); monitor.beginTask(Messages.getString("WspWinExportGmlOperation_0"), waters.length); //$NON-NLS-1$ final File outputDir = m_data.getOutputDir(); if (outputDir.isDirectory()) FileUtils.cleanDirectory(outputDir); final TYPE projectType = m_data.getProjectType(); final String probez = getProjectName(waters); final String roughnessType = m_data.getRoughnessType(); final boolean preferRoghnessClasses = m_data.getPreferRoughnessClasses(); final boolean preferVegetationClasses = m_data.getPreferVegetationClasses(); final WspWinProjectWriter wspWinWriter = new WspWinProjectWriter(probez, projectType, outputDir, roughnessType, preferRoghnessClasses, preferVegetationClasses); for (final WspmWaterBody waterBody : waters) { monitor.subTask(waterBody.getName()); final TuhhReach[] reaches = m_data.getReaches(waterBody); wspWinWriter.addReaches(waterBody, reaches); } wspWinWriter.write(); return Status.OK_STATUS; } catch (final IOException e) { e.printStackTrace(); throw new InvocationTargetException(e); } finally { monitor.done(); } }
From source file:org.keycloak.testsuite.crossdc.AbstractCrossDCTest.java
public void stopCacheServer(ContainerInfo cacheServer) { log.infof("Stopping %s", cacheServer.getQualifier()); containerController.stop(cacheServer.getQualifier()); // Workaround for possible arquillian bug. Needs to cleanup dir manually String setupCleanServerBaseDir = cacheServer.getArquillianContainer().getContainerConfiguration() .getContainerProperties().get("setupCleanServerBaseDir"); String cleanServerBaseDir = cacheServer.getArquillianContainer().getContainerConfiguration() .getContainerProperties().get("cleanServerBaseDir"); if (Boolean.parseBoolean(setupCleanServerBaseDir)) { log.infof("Going to clean directory: %s", cleanServerBaseDir); File dir = new File(cleanServerBaseDir); if (dir.exists()) { try { FileUtils.cleanDirectory(dir); File deploymentsDir = new File(dir, "deployments"); deploymentsDir.mkdir();/*from w ww.j av a2 s. co m*/ } catch (IOException ioe) { throw new RuntimeException("Failed to clean directory: " + cleanServerBaseDir, ioe); } } } log.infof("Stopped %s", cacheServer.getQualifier()); }
From source file:org.kuali.kfs.module.purap.service.ElectronicInvoiceHelperServiceTest.java
@Override protected void setUp() throws Exception { super.setUp(); electronicInvoiceInputFileType = SpringContext.getBean(ElectronicInvoiceInputFileType.class); TestUtils.setSystemParameter(ElectronicInvoiceStep.class, PurapParameterConstants.ElectronicInvoiceParameters.FILE_MOVE_AFTER_LOAD_IND, "yes"); FileUtils.cleanDirectory(new File(electronicInvoiceInputFileType.getDirectoryPath())); unitTestSqlDao = SpringContext.getBean(UnitTestSqlDao.class); }
From source file:org.lexevs.dao.index.indexregistry.MultiIndexRegistry.java
@Override public void destroyIndex(String indexName) { String location = systemVariables.getAutoLoadIndexLocation(); try {//from w w w. j a v a2s .c om Path path = Paths.get(location, indexName); File indexDir2Delete = new File(path.toString()); if (indexDir2Delete.exists()) { try { if (indexDir2Delete.isDirectory()) FileUtils.cleanDirectory(indexDir2Delete); indexDir2Delete.delete(); } catch (Exception e) { FileUtils.deleteQuietly(indexDir2Delete); } } //FileUtils.deleteDirectory(new File(path.toString())); concurrentMetaData.removeIndexMetaDataValue(indexName); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.lpe.common.loadgenerator.scenario.ScenarioRunner.java
private void cleanResultDir(String resultDir) { try {//from w w w.ja v a2s.c o m File file = new File(resultDir); if (file.exists()) { FileUtils.cleanDirectory(new File(resultDir)); } } catch (IOException e) { LOGGER.error("Cannot clean result directory: {} Cause: {}", resultDir, e.getMessage()); throw new RuntimeException("Cannot clean result directory!"); } }
From source file:org.lpe.common.util.system.LpeSystemUtils.java
/** * Extracts a file/folder identified by the URL that resides in the * classpath, into the destiation folder. * //from w w w . j a v a 2 s . co m * @param url * URL of the JAR file * @param dirOfInterest * the name of the directory of interest * @param dest * destination folder * * @throws IOException * ... * @throws URISyntaxException * ... */ public static void extractJARtoTemp(URL url, String dirOfInterest, String dest) throws IOException, URISyntaxException { if (!url.getProtocol().equals("jar")) { throw new IllegalArgumentException("Cannot locate the JAR file."); } // create a temp lib directory File tempJarDirFile = new File(dest); if (!tempJarDirFile.exists()) { boolean ok = tempJarDirFile.mkdir(); if (!ok) { logger.warn("Could not create directory {}", tempJarDirFile.getAbsolutePath()); } } else { FileUtils.cleanDirectory(tempJarDirFile); } String urlStr = url.getFile(); // if (urlStr.startsWith("jar:file:") || urlStr.startsWith("jar:") || // urlStr.startsWith("file:")) { // urlStr = urlStr.replaceFirst("jar:", ""); // urlStr = urlStr.replaceFirst("file:", ""); // } if (urlStr.contains("!")) { final int endIndex = urlStr.indexOf("!"); urlStr = urlStr.substring(0, endIndex); } URI uri = new URI(urlStr); final File jarFile = new File(uri); logger.debug("Unpacking jar file {}...", jarFile.getAbsolutePath()); java.util.jar.JarFile jar = null; InputStream is = null; OutputStream fos = null; try { jar = new JarFile(jarFile); java.util.Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { java.util.jar.JarEntry file = (JarEntry) entries.nextElement(); String destFileName = dest + File.separator + file.getName(); if (destFileName.indexOf(dirOfInterest + File.separator) < 0 && destFileName.indexOf(dirOfInterest + "/") < 0) { continue; } logger.debug("unpacking {}...", file.getName()); java.io.File f = new java.io.File(destFileName); if (file.isDirectory()) { // if its a directory, create it boolean ok = f.mkdir(); if (!ok) { logger.warn("Could not create directory {}", f.getAbsolutePath()); } continue; } is = new BufferedInputStream(jar.getInputStream(file)); fos = new BufferedOutputStream(new FileOutputStream(f)); LpeStreamUtils.pipe(is, fos); } logger.debug("Unpacking jar file done."); } catch (IOException e) { throw e; } finally { if (jar != null) { jar.close(); } if (fos != null) { fos.close(); } if (is != null) { is.close(); } } }
From source file:org.m2latex.mojo.TexFileUtilsImpl.java
public File createTex4htOutputDir(File tempDir) throws MojoExecutionException { File tex4htOutdir = new File(tempDir, TEX4HT_OUTPUT_DIR); if (tex4htOutdir.exists()) { try {/*from w w w .ja v a 2 s .c o m*/ FileUtils.cleanDirectory(tex4htOutdir); } catch (IOException e) { throw new MojoExecutionException("Could not clean TeX4ht output dir: " + tex4htOutdir, e); } } else { tex4htOutdir.mkdirs(); } return tex4htOutdir; }
From source file:org.metaeffekt.dcc.agent.AgentScriptExecutor.java
public void cleanFilesystemLocations(Id<DeploymentId> deploymentId) throws IOException { final ExecutionStateHandler executionStateHandler = getExecutionStateHandler(deploymentId); // clean is symmetric to initialize. as such it affects only the solution folders File[] files = new File[] { executionStateHandler.getStateCacheDirectory(), getTmpDir(deploymentId), getWorkingDir(deploymentId), }; for (File file : files) { if (file.exists()) { FileUtils.cleanDirectory(file); }/*from w w w .jav a2 s . co m*/ } }
From source file:org.mifos.framework.ApplicationInitializer.java
private void copyResources(ServletContext sc) throws IOException { URL protocol = ETLReportDWHelper.class.getClassLoader().getResource("sql/release-upgrades.txt"); ConfigurationLocator configurationLocator = new ConfigurationLocator(); String configPath = configurationLocator.getConfigurationDirectory(); try {//from w w w . j ava 2 s . c o m if (protocol.getProtocol().equals("jar")) { String destinationDirectoryForJobs = configPath + "/ETL/MifosDataWarehouseETL"; String destinationDirectoryForJar = configPath + "/ETL/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar"; String pathFromJar = "/WEB-INF/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar"; String pathFromJobs = "/WEB-INF/MifosDataWarehouseETL/"; if (File.separatorChar == '\\') { destinationDirectoryForJobs = destinationDirectoryForJobs.replaceAll("/", "\\\\"); destinationDirectoryForJar = destinationDirectoryForJar.replaceAll("/", "\\\\"); } File directory = new File(destinationDirectoryForJobs); directory.mkdirs(); FileUtils.cleanDirectory(directory); File jarDest = new File(destinationDirectoryForJar); URL fullPath = sc.getResource(pathFromJar); File f = new File(sc.getResource(pathFromJobs).toString().replace("file:", "")); for (File fileEntry : f.listFiles()) { FileUtils.copyFileToDirectory(fileEntry, directory); logger.info("Copy file: " + fileEntry.getName() + " to: " + directory); } FileUtils.copyURLToFile(fullPath, jarDest); logger.info("Copy file: " + fullPath + " to: " + directory); } } catch (NullPointerException e) { String destinationDirectoryForJobs = configPath + "/ETL/MifosDataWarehouseETL"; String destinationDirectoryForJar = configPath + "/ETL/"; String pathFromJar = sc.getRealPath("/") + "/WEB-INF/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar"; String pathFromJobs = sc.getRealPath("/") + "/WEB-INF/MifosDataWarehouseETL/"; if (File.separatorChar == '\\') { destinationDirectoryForJobs = destinationDirectoryForJobs.replaceAll("/", "\\\\"); destinationDirectoryForJar = destinationDirectoryForJar.replaceAll("/", "\\\\"); } File directory = new File(destinationDirectoryForJobs); directory.mkdirs(); FileUtils.cleanDirectory(directory); logger.info(System.getProperty("user.dir")); File jarDest = new File(destinationDirectoryForJar); URL fullPath = sc.getResource(pathFromJar); File f = new File(pathFromJobs); for (File fileEntry : f.listFiles()) { FileUtils.copyFileToDirectory(fileEntry, directory); logger.info("Copy file: " + fileEntry.getName() + " to: " + directory); } FileUtils.copyFileToDirectory(new File(pathFromJar), jarDest); logger.info("Copy file: " + fullPath + " to: " + directory); } }
From source file:org.mifos.reports.MifosViewerServletContextListener.java
File copyBIRTResourcesFromClassPathToFilesystemDirectory(ServletContext servletContext) { File directory = new File(System.getProperty("java.io.tmpdir"), "MifosBirtFilesExtractedFromClasspath"); try {//from w ww . ja v a 2 s .c o m directory.mkdirs(); FileUtils.cleanDirectory(directory); copyFromClassPathToDirectory(BIRT_RESOURCES_PATTERN, directory); } catch (IOException e) { error(servletContext, "getResources(\"" + ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + BIRT_RESOURCES_PATTERN + "**\") failed: " + e.getMessage(), e); } return directory; }