List of usage examples for org.apache.commons.io FileUtils cleanDirectory
public static void cleanDirectory(File directory) throws IOException
From source file:io.hops.hopsworks.common.security.CertificateMaterializer.java
@PreDestroy public void tearDown() { try {/*from w ww . j a va2 s .com*/ FileUtils.cleanDirectory(new File(transientDir)); } catch (IOException ex) { LOG.log(Level.SEVERE, "Could not clean directory " + transientDir + " Administrator should clean it manually!", ex); } }
From source file:eu.annocultor.reports.ReporterImpl.java
public ReporterImpl(String datasetId, Environment environment) throws Exception { super(environment.getDocDir(), datasetId); FileUtils.cleanDirectory(getReportDir()); init();//from w w w. ja va 2s.c o m this.env = environment; }
From source file:com.universal.storage.UniversalFileStorage.java
/** * This method cleans the context of this storage. This method doesn't remove any file from the storage. * The method will clean the tmp folder to release disk usage. *///from w w w . j a va 2s . com public void clean() throws UniversalIOException { try { FileUtils.cleanDirectory(new File(this.settings.getTmp())); } catch (Exception e) { UniversalIOException error = new UniversalIOException(e.getMessage()); this.triggerOnErrorListeners(error); throw error; } }
From source file:info.archinnov.achilles.embedded.ServerStarter.java
private void cleanCassandraDataFiles(TypedMap parameters) { if (parameters.<Boolean>getTyped(CLEAN_CASSANDRA_DATA_FILES)) { final ImmutableSet<String> dataFolders = ImmutableSet.<String>builder() .add(parameters.<String>getTyped(DATA_FILE_FOLDER)) .add(parameters.<String>getTyped(COMMIT_LOG_FOLDER)) .add(parameters.<String>getTyped(SAVED_CACHES_FOLDER)).build(); for (String dataFolder : dataFolders) { File dataFolderFile = new File(dataFolder); if (dataFolderFile.exists() && dataFolderFile.isDirectory()) { log.info("Cleaning up embedded Cassandra data directory '{}'", dataFolderFile.getAbsolutePath()); try { FileUtils.cleanDirectory(dataFolderFile); } catch (IOException e) { throw new AchillesException(String.format("Cannot clean data folder %s", dataFolder)); }//w w w . ja va 2 s . c o m } } } }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
@AfterEach void dispose() {/*from w w w . j a va 2 s . c om*/ if (user != null) { user.dispose(); } Iterator<MyUser> it = otherUsers.iterator(); while (it.hasNext()) { MyUser other = it.next(); other.dispose(); it.remove(); } try { OV.fetch(); } catch (OpenViduJavaClientException | OpenViduHttpException e1) { log.error("Error fetching sessions: {}", e1.getMessage()); } OV.getActiveSessions().forEach(session -> { try { session.close(); log.info("Session {} successfully closed", session.getSessionId()); } catch (OpenViduJavaClientException e) { log.error("Error closing session: {}", e.getMessage()); } catch (OpenViduHttpException e) { log.error("Error closing session: {}", e.getMessage()); } }); if (isRecordingTest) { try { FileUtils.cleanDirectory(new File("/opt/openvidu/recordings")); } catch (IOException e) { log.error(e.getMessage()); } isRecordingTest = false; } if (isKurentoRestartTest) { this.restartKms(); } }
From source file:com.mycompany.projecta.CommonTasks.java
@Override public String DirectoryToDirectory(String source, String target) throws Exception { try {/*from w w w . j a v a 2 s. c o m*/ File Source = new File(source); File Target = new File(target); FileUtils.copyDirectory(Source, Target); FileUtils.cleanDirectory(Source); } catch (Exception ex) { ex.printStackTrace(System.out); return ex.toString(); } return "passed"; }
From source file:com.isomorphic.maven.mojo.AbstractPackagerMojo.java
/** * Provides some initialization and validation steps around the collection and transformation of an Isomorphic SDK. * //from w w w .j av a 2 s.c o m * @throws MojoExecutionException When any fatal error occurs. * @throws MojoFailureException When any non-fatal error occurs. */ public void execute() throws MojoExecutionException, MojoFailureException { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); if (buildDate == null) { buildDate = dateFormat.format(new Date()); } try { dateFormat.parse(buildDate); } catch (ParseException e) { throw new MojoExecutionException( String.format("buildDate '%s' must take the form yyyy-MM-dd.", buildDate)); } LOGGER.debug("buildDate set to '{}'", buildDate); String buildNumberFormat = "\\d.*\\.\\d.*[d|p]"; if (!buildNumber.matches(buildNumberFormat)) { throw new MojoExecutionException( String.format("buildNumber '%s' must take the form [major].[minor].[d|p]. e.g., 4.1d", buildNumber, buildNumberFormat)); } File basedir = FileUtils.getFile(workdir, product.toString(), license.toString(), buildNumber, buildDate); //add optional modules to the list of downloads List<License> licenses = new ArrayList<License>(); licenses.add(license); if (license == POWER || license == ENTERPRISE) { if (includeAnalytics) { licenses.add(ANALYTICS_MODULE); } if (includeMessaging) { licenses.add(MESSAGING_MODULE); } } //collect the maven artifacts and send them along to the abstract method Set<Module> artifacts = collect(licenses, basedir); File bookmarkable = new File(basedir.getParent(), "latest"); LOGGER.info("Copying distribution to '{}'", bookmarkable.getAbsolutePath()); try { FileUtils.forceMkdir(bookmarkable); FileUtils.cleanDirectory(bookmarkable); FileUtils.copyDirectory(basedir, bookmarkable, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("zip"))); } catch (IOException e) { throw new MojoFailureException("Unable to copy distribution contents", e); } String[] executables = { "bat", "sh", "command" }; Collection<File> scripts = FileUtils.listFiles(basedir, executables, true); scripts.addAll(FileUtils.listFiles(bookmarkable, executables, true)); for (File script : scripts) { script.setExecutable(true); LOGGER.debug("Enabled execute permissions on file '{}'", script.getAbsolutePath()); } doExecute(artifacts); }
From source file:com.thoughtworks.go.remote.work.BuildWork.java
private void createWorkingDirectoryIfNotExist(File buildWorkingDirectory) { if (assignment.shouldCleanWorkingDir() && buildWorkingDirectory.exists()) { try {/*ww w . j a v a2s. c o m*/ FileUtils.cleanDirectory(buildWorkingDirectory); goPublisher.consumeLineWithPrefix( "Cleaning working directory \"" + buildWorkingDirectory.getAbsolutePath() + "\" since stage is configured to clean working directory"); } catch (IOException e) { bomb("Clean working directory is set to true. Unable to clean working directory for agent: " + buildWorkingDirectory.getAbsolutePath() + ", with error: " + e.getMessage()); } } if (!buildWorkingDirectory.exists()) { if (!buildWorkingDirectory.mkdirs()) { bomb("Unable to create working directory for agent: " + buildWorkingDirectory.getAbsolutePath()); } } }
From source file:eu.esdihumboldt.hale.server.templates.war.components.TemplateUploadForm.java
/** * Restore the old content of a template from an archive. * /*w w w .j av a2 s.c o m*/ * @param dir the template directory * @param oldContent the archive with the old content */ protected void restoreContent(File dir, File oldContent) { try { FileUtils.cleanDirectory(dir); } catch (IOException e) { log.error("Error deleting new invalid template content", e); } if (oldContent != null) { // try to restore old content try (InputStream in = new BufferedInputStream(new FileInputStream(oldContent))) { IOUtils.extract(dir, in); } catch (IOException e) { log.error("Error restoring old template content", e); } oldContent.delete(); oldContent = null; templates.forceUpdate(templateId); } }
From source file:com.universal.storage.UniversalFileStorage.java
/** * This method wipes the root folder of a storage, basically, will remove all files and folder in it. * Be careful with this method because in too many cases this action won't provide a rollback action. *//* w ww . java 2 s . c o m*/ public void wipe() throws UniversalIOException { try { FileUtils.cleanDirectory(new File(this.settings.getRoot())); } catch (Exception e) { UniversalIOException error = new UniversalIOException(e.getMessage()); this.triggerOnErrorListeners(error); throw error; } }