List of usage examples for java.nio.file Files delete
public static void delete(Path path) throws IOException
From source file:com.clust4j.algo.DBSCANTests.java
License:asdf
@Test @Override/*from w w w.j av a2 s. co m*/ public void testSerialization() throws IOException, ClassNotFoundException { DBSCAN db = new DBSCAN(data, new DBSCANParameters(0.75).setMinPts(1).setVerbose(true)).fit(); System.out.println(); int a = db.getNumberOfNoisePoints(); db.saveObject(new FileOutputStream(TestSuite.tmpSerPath)); assertTrue(TestSuite.file.exists()); DBSCAN db2 = (DBSCAN) DBSCAN.loadObject(new FileInputStream(TestSuite.tmpSerPath)); assertTrue(a == db2.getNumberOfNoisePoints()); assertTrue(db.equals(db2)); Files.delete(TestSuite.path); }
From source file:org.wso2.carbon.apimgt.hybrid.gateway.usage.publisher.util.UsageFileWriter.java
/** * Rotates the given file. This will compress the file into ZIP format and add a timestamp to file name * * @param fileToRotate ({@link String}) path value of the file to be rotated * @throws UsagePublisherException if there is an exception while compressing or creating the output streams to * the new file/* ww w .j a va 2 s . co m*/ */ public synchronized void rotateFile(String fileToRotate) throws UsagePublisherException { try { closeFileResources(); Path currentPath = Paths.get(fileToRotate); //api-usage-data.dat.1511772769858.046b6c7f-0b8a-43b9-b35d-6489e6daee91.zip Path rotatedPath = Paths.get(fileToRotate + "." + System.currentTimeMillis() + "." + UUID.randomUUID().toString() + MicroGatewayAPIUsageConstants.ZIP_EXTENSION); ZIPUtils.compressFile(currentPath.toString(), rotatedPath.toString()); Files.delete(currentPath); //ReCreate the streams fileOutputStream = new FileOutputStream(filePath.toFile(), true); outputStreamWriter = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8); bufferedWriter = new BufferedWriter(outputStreamWriter); } catch (ZIPException | IOException e) { throw new UsagePublisherException("Error occurred while rotating the file : " + fileToRotate, e); } }
From source file:org.fim.FullScenarioTest.java
private void doSomeModifications() throws IOException { Files.createDirectories(dir01); Files.move(rootDir.resolve("file01"), dir01.resolve("file01")); tool.touchLastModified("file02"); Files.copy(rootDir.resolve("file03"), rootDir.resolve("file03.dup1")); Files.copy(rootDir.resolve("file03"), rootDir.resolve("file03.dup2")); tool.setFileContent("file04", "foo"); Files.copy(rootDir.resolve("file05"), rootDir.resolve("file11")); tool.setFileContent("file05", "bar"); Files.delete(rootDir.resolve("file06")); Files.copy(rootDir.resolve("file07"), rootDir.resolve("file07.dup1")); tool.setFileContent("file12", "New file 12"); }
From source file:io.divolte.server.filesinks.hdfs.FileFlusherLocalHdfsTest.java
private void deleteQuietly(final Path p) { try {/* w w w .ja v a 2s .co m*/ Files.delete(p); } catch (final Exception e) { logger.debug("Ignoring failure while deleting file: " + p, e); } }
From source file:de.appsolve.padelcampus.utils.HtmlResourceUtil.java
private String concatenateCss(ServletContext context, Path path, Path outFile) throws FileNotFoundException, IOException { DirectoryStream<Path> cssFiles = Files.newDirectoryStream(path, "*.css"); if (Files.exists(outFile)) { Files.delete(outFile); }//from w w w . ja v a 2 s. c om List<Path> sortedFiles = new ArrayList<>(); for (Path cssFile : cssFiles) { sortedFiles.add(cssFile); } Collections.sort(sortedFiles, new PathByFileNameComparator()); for (Path cssFile : sortedFiles) { Files.write(outFile, Files.readAllBytes(cssFile), StandardOpenOption.CREATE, StandardOpenOption.APPEND); } byte[] cssData; if (Files.exists(outFile)) { cssData = Files.readAllBytes(outFile); } else { //read from classpath InputStream is = context.getResourceAsStream(ALL_MIN_CSS); cssData = IOUtils.toByteArray(is); } String css = new String(cssData, Constants.UTF8); return css; }
From source file:ru.codemine.ccms.counters.kondor.KondorClient.java
@Override public List<Counter> getCounters(Shop shop) { File dbfFile = ftpDownload(shop); if (!dbfFile.exists()) { log.warn(".dbf : " + shop.getName()); return null; }//from w ww. ja va 2s .c om List<Counter> result = DbfProcessor.loadData(dbfFile, new DbfRowMapper<Counter>() { @Override public Counter mapRow(Object[] row) { Counter c = new Counter(); String dateStr = new String(DbfUtils.trimLeftSpaces((byte[]) row[0])); DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YY"); DateTime dt = formatter.parseDateTime(dateStr); c.setDate(dt); Number inNumber = (Number) row[1]; c.setIn(inNumber.intValue()); Number outNumber = (Number) row[2]; c.setOut(outNumber.intValue()); return c; } }); for (Counter counter : result) counter.setShop(shop); try { Files.delete(dbfFile.toPath()); } catch (IOException e) { log.error("? .dbf : " + dbfFile.getPath()); } return result; }
From source file:com.laishidua.mobilecloud.ghostmyselfie.controller.GhostMySelfieController.java
/** * Provides the average ghostmyselfie rating for a ghostmyselfie * /*w w w . j a v a 2 s .c o m*/ * @param id : id of the ghostmyselfie to retrieve * @param response : http response, exposed to allow manipulation like setting * error codes * @return : an AverageGhostMySelfieRating object * @throws IOException */ @RequestMapping(value = GhostMySelfieSvcApi.GHOSTMYSELFIE_SVC_PATH + "/delete/{id}", method = RequestMethod.GET) public @ResponseBody Integer deleteGhostMySelfieById(@PathVariable(GhostMySelfieSvcApi.ID_PARAMETER) long id, Principal p, HttpServletResponse response) throws IOException { GhostMySelfie gms1 = ghostMySelphie.findOne(id); // let's see if the ghostmyselfie exists already, according to its hashcode GhostMySelfie gms2 = ghostMySelphie.findExactGhostMySelfieById(id, p.getName()); if (gms1 != null && gms2 != null) { try { Path selfie = ghostMySelfieDataMgr.getGhostMySelfiePath(gms1); Files.delete(selfie); } catch (Exception e) { e.printStackTrace(); } ghostMySelphie.delete(gms1); return 1; } else if (gms1 != null && gms2 == null) { response.sendError(401, "Sorry, your cannot delete this Selfie because you are not the owner."); return 0; } else { response.sendError(404, "Sorry, your ghostmyselfie is in another castle."); return 0; } }
From source file:org.cirdles.webServices.calamari.PrawnFileHandlerService.java
public Path generateReportsZip(String myFileName, InputStream prawnFile, boolean useSBM, boolean userLinFits, String firstLetterRM) throws IOException, JAXBException, SAXException { String fileName = myFileName; if (myFileName == null) { fileName = DEFAULT_PRAWNFILE_NAME; }/* w w w . ja v a2s .co m*/ Path uploadDirectory = Files.createTempDirectory("upload"); Path prawnFilePathZip = uploadDirectory.resolve("prawn-file.zip"); Files.copy(prawnFile, prawnFilePathZip); //file path string to extracted xml String extract = extract(prawnFilePathZip.toFile(), uploadDirectory.toFile()); Path calamarirReportsFolderAlias = Files.createTempDirectory("reports-destination"); File reportsDestinationFile = calamarirReportsFolderAlias.toFile(); reportsEngine.setFolderToWriteCalamariReports(reportsDestinationFile); fileName = FilenameUtils.removeExtension(fileName); // this gives reportengine the name of the Prawnfile for use in report names prawnFileHandler.initReportsEngineWithCurrentPrawnFileName(fileName); prawnFileHandler.writeReportsFromPrawnFile(extract, useSBM, userLinFits, firstLetterRM); Files.delete(prawnFilePathZip); Path reportsFolder = Paths.get(reportsEngine.getFolderToWriteCalamariReportsPath()).getParent() .toAbsolutePath(); Path reports = Files.list(reportsFolder).findFirst().orElseThrow(() -> new IllegalStateException()); Path reportsZip = zip(reports); recursiveDelete(reports); return reportsZip; }
From source file:org.apache.tika.eval.TikaEvalCLI.java
private void handleProfile(String[] subsetArgs) throws Exception { List<String> argList = new ArrayList(Arrays.asList(subsetArgs)); boolean containsBC = false; String inputDir = null;//from ww w . jav a2s.c o m String extracts = null; String alterExtract = null; //confirm there's a batch-config file for (int i = 0; i < argList.size(); i++) { String arg = argList.get(i); if (arg.equals("-bc")) { containsBC = true; } else if (arg.equals("-inputDir")) { if (i + 1 >= argList.size()) { System.err.println("Must specify directory after -inputDir"); ExtractProfiler.USAGE(); return; } inputDir = argList.get(i + 1); i++; } else if (arg.equals("-extracts")) { if (i + 1 >= argList.size()) { System.err.println("Must specify directory after -extracts"); ExtractProfiler.USAGE(); return; } extracts = argList.get(i + 1); i++; } else if (arg.equals("-alterExtract")) { if (i + 1 >= argList.size()) { System.err.println("Must specify type 'as_is', 'first_only' or " + "'concatenate_content' after -alterExtract"); ExtractComparer.USAGE(); return; } alterExtract = argList.get(i + 1); i++; } } if (alterExtract != null && !alterExtract.equals("as_is") && !alterExtract.equals("concatenate_content") && !alterExtract.equals("first_only")) { System.out.println("Sorry, I don't understand:" + alterExtract + ". The values must be one of: as_is, first_only, concatenate_content"); ExtractProfiler.USAGE(); return; } //need to specify each in this commandline //if only extracts is passed to tika-batch, //the crawler will see no inputDir and start crawling "input". //this allows the user to specify either extracts or inputDir if (extracts == null && inputDir != null) { argList.add("-extracts"); argList.add(inputDir); } else if (inputDir == null && extracts != null) { argList.add("-inputDir"); argList.add(extracts); } Path tmpBCConfig = null; try { tmpBCConfig = Files.createTempFile("tika-eval-profiler", ".xml"); if (!containsBC) { Files.copy(this.getClass().getResourceAsStream("/tika-eval-profiler-config.xml"), tmpBCConfig, StandardCopyOption.REPLACE_EXISTING); argList.add("-bc"); argList.add(tmpBCConfig.toAbsolutePath().toString()); } String[] updatedArgs = argList.toArray(new String[argList.size()]); DefaultParser defaultCLIParser = new DefaultParser(); try { CommandLine commandLine = defaultCLIParser.parse(ExtractProfiler.OPTIONS, updatedArgs); if (commandLine.hasOption("db") && commandLine.hasOption("jdbc")) { System.out.println("Please specify either the default -db or the full -jdbc, not both"); ExtractProfiler.USAGE(); return; } } catch (ParseException e) { System.out.println(e.getMessage() + "\n"); ExtractProfiler.USAGE(); return; } FSBatchProcessCLI.main(updatedArgs); } finally { if (tmpBCConfig != null && Files.isRegularFile(tmpBCConfig)) { Files.delete(tmpBCConfig); } } }
From source file:it.reexon.lib.files.FileUtils.java
/** * Deletes a file. /*w w w. jav a2 s . com*/ * * @param file the path to the file * @return boolean * @throws IOException if an I/O error occurs * @throws IllegalArgumentException if file is null */ public static boolean deleteFile(Path file) throws IOException { if ((file == null)) throw new IllegalArgumentException("file cannot be null"); try { if (file.toFile().canWrite()) { Files.delete(file); } return !Files.exists(file, LinkOption.NOFOLLOW_LINKS); } catch (IOException e) { e.printStackTrace(); throw new IOException("An IO exception occured while deleting file '" + file + "' with error:" + e.getLocalizedMessage()); } }