List of usage examples for java.nio.file Files delete
public static void delete(Path path) throws IOException
From source file:org.apache.solr.schema.TestManagedSchema.java
public void testAddFieldThenReload() throws Exception { deleteCore();// w w w . j a v a2s .c om File managedSchemaFile = new File(tmpConfDir, "managed-schema"); Files.delete(managedSchemaFile.toPath()); // Delete managed-schema so it won't block parsing a new schema System.setProperty("managed.schema.mutable", "true"); initCore("solrconfig-managed-schema.xml", "schema-one-field-no-dynamic-field.xml", tmpSolrHome.getPath()); String fieldName = "new_text_field"; assertNull("Field '" + fieldName + "' is present in the schema", h.getCore().getLatestSchema().getFieldOrNull(fieldName)); Map<String, Object> options = new HashMap<>(); IndexSchema oldSchema = h.getCore().getLatestSchema(); String fieldType = "text"; SchemaField newField = oldSchema.newField(fieldName, fieldType, options); IndexSchema newSchema = oldSchema.addField(newField); h.getCore().setLatestSchema(newSchema); h.reload(); }
From source file:org.finra.dm.dao.Log4jOverridableConfigurerTest.java
/** * Cleanup the Log4J files created.//from w ww. ja va2s . co m * * @param configPath the configuration path. * @param outputPath the output path. * * @throws IOException if any problems were encountered while cleaning up the files. */ private void cleanup(Path configPath, Path outputPath) throws IOException { // Shutdown the logging which will release the lock on the output file. Log4jConfigurer.shutdownLogging(); // Delete the Log4J configuration we created in the setup. if (Files.exists(configPath)) { Files.delete(configPath); } // If we created a Log4J output file (not always), then delete it. if (Files.exists(outputPath)) { Files.delete(outputPath); } }
From source file:org.niord.core.batch.BatchService.java
/** * Called every hour to clean up the batch job "[jobName]/execution" folders for expired files *//*from www . j a v a 2s .c o m*/ @Schedule(persistent = false, second = "30", minute = "42", hour = "*/1") protected void cleanUpExpiredBatchJobFiles() { long t0 = System.currentTimeMillis(); // Resolve the list of batch job "execution" folders List<Path> executionFolders = getBatchJobSubFolders("execution"); // Compute the expiry time Calendar expiryDate = Calendar.getInstance(); expiryDate.add(Calendar.DATE, -batchFileExpiryDays); // Clean up the files executionFolders.forEach(folder -> { try { Files.walkFileTree(folder, new SimpleFileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (isDirEmpty(dir)) { log.debug("Deleting batch job directory :" + dir); Files.delete(dir); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (FileUtils.isFileOlder(file.toFile(), expiryDate.getTime())) { log.debug("Deleting batch job file :" + file); Files.delete(file); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.error("Failed cleaning up " + folder + " batch job directory: " + e.getMessage(), e); } }); log.debug(String.format("Cleaned up expired batch job files in %d ms", System.currentTimeMillis() - t0)); }
From source file:com.clust4j.data.TestDataSet.java
@Test public void testWrite1() throws IOException { String path = "iris.csv"; final File file = new File(path); Path ppath = FileSystems.getDefault().getPath(path); try {/*from ww w. j av a 2 s.c o m*/ TestSuite.IRIS_DATASET.toFlatFile(true, file); } finally { Files.delete(ppath); } }
From source file:com.clust4j.data.TestDataSet.java
@Test public void testWrite2() throws IOException { String path = "iris.csv"; final File file = new File(path); Path ppath = FileSystems.getDefault().getPath(path); try {/*from ww w . ja v a2 s . c om*/ TestSuite.IRIS_DATASET.toFlatFile(false, file); } finally { Files.delete(ppath); } }
From source file:org.codice.ddf.security.migratable.impl.SecurityMigratableTest.java
/** * Verify that when the PDP file, polciy files, and CRL do not exists, the export and import * succeed.//from ww w . j a va 2 s . c o m */ @Test public void testDoExportAndDoImportWhenNoFiles() throws IOException { // Setup export Path exportDir = tempDir.getRoot().toPath().toRealPath(); // Comment out CRL in etc/ws-security/server/encryption.properties Path serverEncptProps = ddfHome.resolve(Paths.get("etc", "ws-security", "server", "encryption.properties")); String tag = String.format(DDF_EXPORTED_TAG_TEMPLATE, DDF_EXPORTED_HOME); writeProperties(serverEncptProps, "_" + CRL_PROP_KEY, CRL.toString(), String.format("%s&%s", serverEncptProps.toRealPath().toString(), tag)); // Remove PDP file Path xacmlPolicy = ddfHome.resolve(PDP_POLICIES_DIR).resolve(XACML_POLICY); Files.delete(xacmlPolicy); // Remove policy files for (final String file : POLICY_FILES) { Path policy = ddfHome.resolve(SECURITY_POLICIES_DIR).resolve(file); Files.delete(policy); } SecurityMigratable eSecurityMigratable = new SecurityMigratable(); List<Migratable> eMigratables = Arrays.asList(eSecurityMigratable); ConfigurationMigrationManager eConfigurationMigrationManager = new ConfigurationMigrationManager( eMigratables, systemService); // Perform export MigrationReport exportReport = eConfigurationMigrationManager.doExport(exportDir, this::print); // Verify export assertThat("The export report has errors.", exportReport.hasErrors(), is(false)); assertThat("The export report has warnings.", exportReport.hasWarnings(), is(false)); assertThat("Export was not successful.", exportReport.wasSuccessful(), is(true)); String exportedZipBaseName = String.format("%s-%s.dar", SUPPORTED_BRANDING, SUPPORTED_PRODUCT_VERSION); Path exportedZip = exportDir.resolve(exportedZipBaseName).toRealPath(); assertThat("Export zip does not exist.", exportedZip.toFile().exists(), is(true)); assertThat("Exported zip is empty.", exportedZip.toFile().length(), greaterThan(0L)); // Setup import setup(DDF_IMPORTED_HOME, DDF_IMPORTED_TAG, SUPPORTED_PRODUCT_VERSION); SecurityMigratable iSecurityMigratable = new SecurityMigratable(); List<Migratable> iMigratables = Arrays.asList(iSecurityMigratable); ConfigurationMigrationManager iConfigurationMigrationManager = new ConfigurationMigrationManager( iMigratables, systemService); MigrationReport importReport = iConfigurationMigrationManager.doImport(exportDir, this::print); // Verify import assertThat("The import report has errors.", importReport.hasErrors(), is(false)); assertThat("The import report has warnings.", importReport.hasWarnings(), is(false)); assertThat("Import was not successful.", importReport.wasSuccessful(), is(true)); }
From source file:org.apache.nifi.controller.repository.FileSystemRepository.java
private void removeIncompleteContent(final Path fileToRemove) { String fileDescription = null; try {//from w ww . j a v a 2 s .c o m fileDescription = fileToRemove.toFile().getAbsolutePath() + " (" + Files.size(fileToRemove) + " bytes)"; } catch (final IOException e) { fileDescription = fileToRemove.toFile().getAbsolutePath() + " (unknown file size)"; } LOG.info("Found unknown file {} in File System Repository; {} file", fileDescription, archiveData ? "archiving" : "removing"); try { if (archiveData) { archive(fileToRemove); } else { Files.delete(fileToRemove); } } catch (final IOException e) { final String action = archiveData ? "archive" : "remove"; LOG.warn("Unable to {} unknown file {} from File System Repository due to {}", action, fileDescription, e.toString()); LOG.warn("", e); } }
From source file:edu.purdue.cybercenter.dm.storage.GlobusStorageFileManager.java
private void removeSymbolicLinks(List<String> fileLinks) throws IOException { for (String fileLink : fileLinks) { Path linkPath = FileSystems.getDefault().getPath(fileLink); //if (Files.isSymbolicLink(linkPath)) { Files.delete(linkPath); //}//from w w w .ja v a2 s . com } }
From source file:com.clust4j.data.TestDataSet.java
@Test public void testWrite3() throws IOException { String path = "iris.csv"; final File file = new File(path); Path ppath = FileSystems.getDefault().getPath(path); try {/*from w ww.j ava 2 s .c o m*/ TestSuite.IRIS_DATASET.toFlatFile(true, file, '|'); } finally { Files.delete(ppath); } }
From source file:org.finra.herd.dao.Log4jOverridableConfigurerTest.java
/** * Cleanup the Log4J files created./*from w ww . j a v a 2 s .co m*/ * * @param configPath the configuration path. * @param outputPath the output path. * * @throws IOException if any problems were encountered while cleaning up the files. */ private void cleanup(Path configPath, Path outputPath) throws IOException { // Shutdown the logging which will release the lock on the output file. loggingHelper.shutdownLogging(); // Delete the Log4J configuration we created in the setup. if (Files.exists(configPath)) { Files.delete(configPath); } // If we created a Log4J output file (not always), then delete it. if (Files.exists(outputPath)) { Files.delete(outputPath); } }