List of usage examples for java.nio.file Files delete
public static void delete(Path path) throws IOException
From source file:com.clust4j.algo.HDBSCANTests.java
@Test @Override//from w w w.ja va 2 s . c o m public void testSerialization() throws IOException, ClassNotFoundException { HDBSCAN hd = new HDBSCAN(DATA, new HDBSCANParameters(1).setVerbose(true)).fit(); System.out.println(); final int[] labels = hd.getLabels(); hd.saveObject(new FileOutputStream(TestSuite.tmpSerPath)); assertTrue(TestSuite.file.exists()); HDBSCAN hd2 = (HDBSCAN) HDBSCAN.loadObject(new FileInputStream(TestSuite.tmpSerPath)); assertTrue(VecUtils.equalsExactly(hd2.getLabels(), labels)); assertTrue(hd.equals(hd2)); Files.delete(TestSuite.path); }
From source file:org.apache.solr.schema.TestManagedSchema.java
public void testAddWithSchemaCodecFactory() throws Exception { deleteCore();/* w w w .j a v a2 s. c o m*/ 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_codec.xml", tmpSolrHome.getPath()); String uniqueKey = "string_f"; assertNotNull("Unique key field '" + uniqueKey + "' is not present in the schema", h.getCore().getLatestSchema().getFieldOrNull(uniqueKey)); String fieldName = "string_disk_new_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 = "string_disk"; SchemaField newField = oldSchema.newField(fieldName, fieldType, options); IndexSchema newSchema = oldSchema.addField(newField); h.getCore().setLatestSchema(newSchema); assertU(adoc(fieldName, "thing", uniqueKey, "aBc")); assertU(commit()); assertQ(req(fieldName + ":thing"), "//*[@numFound='1']"); }
From source file:org.apache.nifi.processors.standard.FetchFile.java
protected void delete(final File file) throws IOException { Files.delete(file.toPath()); }
From source file:org.codice.ddf.platform.migratable.impl.PlatformMigratableTest.java
/** * Verifies that when a required files is missing, the export fails and no zip file is created. *//*w ww . ja v a 2 s. c o m*/ @Test public void testDoExportRequiredFileNotExported() throws IOException { // Setup export Path exportDir = tempDir.getRoot().toPath().toRealPath(); // Delete etc/system.properties. This file is required, so we should // should get an export error. Files.delete(ddfHome.resolve("etc").resolve("custom.system.properties").toRealPath()); MigrationReport exportReport = doExport(exportDir); // Verify export assertThat("The export report doesn't not have errors.", exportReport.hasErrors(), is(true)); assertThat("The export report has warnings.", exportReport.hasWarnings(), is(false)); assertThat("Export was successful.", exportReport.wasSuccessful(), is(false)); String exportedZipBaseName = String.format("%s-%s.dar", SUPPORTED_BRANDING, SUPPORTED_VERSION); Path exportedZip = exportDir.resolve(exportedZipBaseName); assertThat(String.format("Export zip [%s] exists.", exportedZip), exportedZip.toFile().exists(), is(false)); }
From source file:org.dihedron.strutlets.ActionContext.java
/** * Cleans up the internal status of the <code>ActionContextImpl</code> in order to * avoid memory leaks due to persisting portal objects stored in the per-thread * local storage; afterwards it removes the thread local entry altogether, so * the application server does not complain about left-over data in TLS when * re-deploying the portlet./*from w w w .j a va 2s. co m*/ */ static void unbindContext() { logger.debug("removing action context for thread {}", Thread.currentThread().getId()); getContext().request = null; getContext().response = null; getContext().portlet = null; getContext().configuration = null; getContext().server = null; getContext().portal = null; // remove all files if this is a multipart/form-data request, because // the file tracker does not seem to work as expected if (isMultiPartRequest()) { for (Entry<String, FileItem> entry : getContext().parts.entrySet()) { if (!entry.getValue().isFormField() && !entry.getValue().isInMemory()) { File file = ((DiskFileItem) entry.getValue()).getStoreLocation(); try { logger.trace("removing uploaded file '{}' from disk...", file.getAbsolutePath()); Files.delete(file.toPath()); logger.trace("... file deleted"); } catch (IOException e) { logger.trace("... error deleting file", e); } } } } getContext().parts = null; // if(getContext().parts != null) { // for(Entry<String, FileItem> entry : getContext().parts.entrySet()) { // FileItem part = entry.getValue(); // if(!part.isFormField() && !part.isInMemory()) { // logger.trace("releasing on-disk uploaded file '{}'", part.getFieldName()); // // } // } // } context.remove(); }
From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java
public static void deleteDirectory(String path) { try {/* w w w . j av a 2 s.c o m*/ Path directory = Paths.get(path); Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); } catch (IOException ex) { logger.severe(ex.getMessage()); } }
From source file:de.qucosa.webapi.v1.DocumentResource.java
private void purgeFilesAndCorrespondingDatastreams(String pid, List<String> purgeDatastreamList) throws FedoraClientException, URISyntaxException { for (String dsid : purgeDatastreamList) { DatastreamProfile datastreamProfile = fedoraRepository.getDatastreamProfile(pid, dsid); String path = datastreamProfile.getDsLocation(); try {/*from w w w . jav a2 s . com*/ Files.delete(new File(new URI(path)).toPath()); } catch (IOException ex) { log.error("Deleting file {} failed: {}", path, ex.toString()); log.warn("Datastream {}/{} gets purged without removing the file", pid, dsid); } fedoraRepository.purgeDatastream(pid, dsid); } }
From source file:org.kitodo.production.services.command.KitodoScriptService.java
/** * Delete TiffHeader file from given processes. * * @param processes//from w ww . j ava 2s . c o m * list of Process objects */ public void deleteTiffHeaderFile(List<Process> processes) { for (Process process : processes) { try { File tiffHeaderFile = new File(fileService.getImagesDirectory(process) + "tiffwriter.conf"); if (tiffHeaderFile.exists()) { Files.delete(tiffHeaderFile.toPath()); } Helper.setMessage(KITODO_SCRIPT_FIELD, "TiffHeaderFile deleted: ", process.getTitle()); } catch (IOException | RuntimeException e) { Helper.setErrorMessage(KITODO_SCRIPT_FIELD, "Error while deleting TiffHeader", logger, e); } } Helper.setMessage(KITODO_SCRIPT_FIELD, "", "deleteTiffHeaderFile finished"); }
From source file:org.apache.solr.schema.TestManagedSchema.java
public void testAddWithSchemaSimilarityFactory() throws Exception { deleteCore();//w w w . j av a 2 s. c o m 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-bm25.xml", tmpSolrHome.getPath()); String uniqueKey = "id"; assertNotNull("Unique key field '" + uniqueKey + "' is not present in the schema", h.getCore().getLatestSchema().getFieldOrNull(uniqueKey)); 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); assertU(adoc(fieldName, "thing", uniqueKey, "123")); assertU(commit()); assertQ(req(fieldName + ":thing"), "//*[@numFound='1']"); }