List of usage examples for java.nio.file Files delete
public static void delete(Path path) throws IOException
From source file:org.kitodo.production.forms.MassImportForm.java
private void removeFiles() throws IOException { if (Objects.nonNull(this.importFile)) { Files.delete(this.importFile.toPath()); this.importFile = null; }// ww w .j a va 2s . c om if (Objects.nonNull(selectedFilenames) && !selectedFilenames.isEmpty()) { this.plugin.deleteFiles(this.selectedFilenames); } }
From source file:com.streamsets.datacollector.io.DataStore.java
/** * This method must be used to commit contents written to the output stream which is obtained by calling * the {@link #getOutputStream()} method. This method closes the argument output stream. * * Example usage:/*from w w w. j ava2 s. com*/ * * DataStore dataStore = new DataStore(...); * try (OutputStream os = dataStore.getOutputStream()) { * os.write(..); * dataStore.commit(os); * } catch (IOException e) { * ... * } finally { * dataStore.release(); * } * * @throws IOException */ public void commit(OutputStream out) throws IOException { // close the stream in order to flush the contents into the disk Utils.checkNotNull(out, "Argument output stream cannot be null"); Utils.checkState(stream == out, "The argument output stream must be the same as the output stream obtained " + "from this data store instance"); out.close(); Files.move(fileTmp, fileNew); LOG.trace("Committing write, move '{}' to '{}'", fileTmp, fileNew); Files.move(fileNew, file); LOG.trace("Committing write, move '{}' to '{}'", fileNew, file); if (Files.exists(fileOld)) { Files.delete(fileOld); LOG.trace("Committing write, deleting '{}'", fileOld); } LOG.trace("Committed"); }
From source file:io.divolte.server.hdfs.HdfsFlusherTest.java
private void deleteQuietly(Path p) { try {/*from ww w . j a v a2 s. c o m*/ Files.delete(p); } catch (final Exception e) { logger.debug("Ignoring failure while deleting file: " + p, e); } }
From source file:com.romeikat.datamessie.core.base.util.FileUtil.java
private Path createZipFile(final String dir, String filename, final List<Path> files) throws IOException { filename = normalizeFilename(filename); // Create ZIP file Path zipFile = Paths.get(dir, filename + ".zip"); zipFile = getNonExisting(zipFile);/*from w w w .j a va2 s . co m*/ Files.createFile(zipFile); final URI zipUri = URI.create("jar:file:" + zipFile.toUri().getPath()); Files.delete(zipFile); final Map<String, String> zipProperties = new HashMap<String, String>(); zipProperties.put("create", "true"); zipProperties.put("encoding", "UTF-8"); final FileSystem zipFS = FileSystems.newFileSystem(zipUri, zipProperties); // Copy TXT files to ZIP file for (final Path file : files) { final Path fileToZip = file; final Path pathInZipfile = zipFS.getPath(file.getFileName().toString()); Files.copy(fileToZip, pathInZipfile); } // Done zipFS.close(); return zipFile; }
From source file:org.carcv.impl.core.io.FFMPEGVideoHandlerIT.java
/** * Test method for//from w w w. j a v a 2s .c o m * {@link org.carcv.impl.core.io.FFMPEGVideoHandler#generateVideoAsStream(org.carcv.core.model.file.FileEntry, java.io.OutputStream)} * . * * @throws IOException */ @Test public void testGenerateVideoAsStreamFileEntryOutputStream() throws IOException { Path outTemp = Files.createTempFile("testvideo", ".h264"); OutputStream out = Files.newOutputStream(outTemp); FFMPEGVideoHandler.generateVideoAsStream(entry, out); assertNotNull(out); assertTrue(Files.exists(outTemp)); assertTrue(Files.isRegularFile(outTemp)); Files.delete(outTemp); }
From source file:com.ejisto.util.IOUtils.java
public static boolean emptyDir(File file) { Path directory = file.toPath(); if (!Files.isDirectory(directory)) { return true; }/*from w w w . ja v a 2 s . c o m*/ try { 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 { if (exc == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } return FileVisitResult.TERMINATE; } }); } catch (IOException e) { IOUtils.log.error(format("error while trying to empty the directory %s", directory.toString()), e); return false; } return true; }
From source file:org.apache.solr.schema.TestManagedSchema.java
public void testAddFieldPersistence() throws Exception { assertSchemaResource(collection, "managed-schema"); deleteCore();//from ww w . j a v a2 s . co 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-one-field-no-dynamic-field.xml", tmpSolrHome.getPath()); assertTrue(managedSchemaFile.exists()); String managedSchemaContents = FileUtils.readFileToString(managedSchemaFile, "UTF-8"); assertFalse(managedSchemaContents.contains("\"new_field\"")); Map<String, Object> options = new HashMap<>(); options.put("stored", "false"); IndexSchema oldSchema = h.getCore().getLatestSchema(); String fieldName = "new_field"; String fieldType = "string"; SchemaField newField = oldSchema.newField(fieldName, fieldType, options); IndexSchema newSchema = oldSchema.addField(newField); h.getCore().setLatestSchema(newSchema); assertTrue(managedSchemaFile.exists()); FileInputStream stream = new FileInputStream(managedSchemaFile); managedSchemaContents = IOUtils.toString(stream, "UTF-8"); stream.close(); // Explicitly close so that Windows can delete this file assertTrue(managedSchemaContents.contains("<field name=\"new_field\" type=\"string\" stored=\"false\"/>")); }
From source file:dk.dma.msinm.common.repo.RepositoryService.java
/** * Deletes the file specified by the path * @param path the path/*from w ww . j av a 2s. c o m*/ * @return the response */ @DELETE @javax.ws.rs.Path("/file/{file:.+}") //@RolesAllowed({ "editor" }) public String deleteFile(@PathParam("file") String path) throws IOException { // TODO: The @RolesAllowed annotation has been commented out for now, because deleting // a file with a space in the file name would yield an unauthorized-exception. WTF!!! // Consider checking the role programmatically via the UserService... Path f = repoRoot.resolve(path); if (Files.notExists(f) || Files.isDirectory(f)) { log.warn("Failed deleting file: " + f); throw new WebApplicationException(404); } Files.delete(f); log.info("Deleted file " + f); return "OK"; }
From source file:org.niord.core.repo.RepositoryService.java
/** * Deletes the file specified by the path * @param path the path/*from w w w . java2 s.c o m*/ * @return the response */ @DELETE @javax.ws.rs.Path("/file/{file:.+}") @Produces("text/plain") @RolesAllowed(Roles.EDITOR) public Response deleteFile(@PathParam("file") String path) throws IOException { Path f = repoRoot.resolve(path); if (Files.notExists(f) || Files.isDirectory(f)) { log.warn("Failed deleting non-existing file: " + f); return Response.status(HttpServletResponse.SC_NOT_FOUND).entity("File not found: " + path).build(); } Files.delete(f); log.info("Deleted file " + f); return Response.ok("File deleted " + f).build(); }
From source file:org.pentaho.di.core.plugins.PluginFolderTest.java
private void cleanTempDir(Path path) throws IOException { Files.walkFileTree(path, new FileVisitor<Path>() { @Override/*from w w w .j a va2 s. c o m*/ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); }