List of usage examples for java.nio.file Files delete
public static void delete(Path path) throws IOException
From source file:ch.puzzle.itc.mobiliar.business.utils.SecureFileLoaderTest.java
@Test public void testIsFileLocatedInDirectorySymbolicLinkOk() throws IOException { //symlinks work only on unix Assume.assumeTrue(isUnix());/* www . j a va 2 s. c o m*/ Path symlink = Paths.get(dir.toString(), "symlink.txt"); //We create a symbolic link inside of the permitted folder pointing to a file inside of the permitted folder. This should be ok. Files.createSymbolicLink(symlink, f); Assert.assertTrue(fileLoader.isFileLocatedInDirectory(dir, symlink)); Files.delete(symlink); }
From source file:com.clust4j.algo.NearestNeighborsTests.java
@Test @Override//from w w w .j a v a2s . c o m public void testSerialization() throws IOException, ClassNotFoundException { NearestNeighbors nn = new NearestNeighbors(data, new NearestNeighborsParameters(5).setVerbose(true)).fit(); final int[][] c = nn.getNeighbors().getIndices(); nn.saveObject(new FileOutputStream(TestSuite.tmpSerPath)); assertTrue(TestSuite.file.exists()); NearestNeighbors nn2 = (NearestNeighbors) NearestNeighbors .loadObject(new FileInputStream(TestSuite.tmpSerPath)); assertTrue(MatUtils.equalsExactly(nn2.getNeighbors().getIndices(), c)); assertTrue(nn2.equals(nn)); assertTrue(nn.equals(nn)); // test the ref return assertFalse(nn.equals(new Object())); Files.delete(TestSuite.path); }
From source file:org.lable.oss.dynamicconfig.provider.FileBasedConfigSourceIT.java
@Ignore @Test/*ww w . ja v a2 s. c om*/ public void testListen() throws URISyntaxException, InterruptedException, IOException, ConfigurationException { final String VALUE_A = "key: AAA\n"; final String VALUE_B = "key: BBB\n"; final String VALUE_C = "key: CCC\n"; File configFile = File.createTempFile("configuration", ".yml"); Files.write(configFile.toPath(), VALUE_A.getBytes()); FileBasedConfigSource source = new FileBasedConfigSource(); Configuration config = new BaseConfiguration(); config.setProperty("path", configFile.getPath()); source.configure(config); HierarchicalConfigurationDeserializer deserializer = new YamlDeserializer(); final List<String> results = new ArrayList<>(); source.listen(deserializer, fresh -> results.add(fresh.getString("key"))); // Sleep a little bit between file modification to ensure we have a testable sequence of events. TimeUnit.MILLISECONDS.sleep(200); // Change the contents of the file. Triggers the listener the first time. Files.write(configFile.toPath(), VALUE_B.getBytes()); TimeUnit.MILLISECONDS.sleep(200); // Change it again. Triggers the listener a second time. Files.write(configFile.toPath(), VALUE_A.getBytes()); TimeUnit.MILLISECONDS.sleep(200); // Remove the file. Has no impact on the listener. Files.delete(configFile.toPath()); TimeUnit.MILLISECONDS.sleep(200); // And recreate it. Triggers the listener. Files.write(configFile.toPath(), VALUE_C.getBytes()); TimeUnit.MILLISECONDS.sleep(200); assertThat(results.get(0), is("BBB")); assertThat(results.get(1), is("AAA")); assertThat(results.get(2), is("CCC")); assertThat(results.size(), is(3)); }
From source file:org.fim.tooling.RepositoryTool.java
public void setFileContent(Path file, String content) throws IOException { if (Files.exists(file)) { Files.delete(file); }/* w w w . j a v a2 s . c o m*/ // Creates a big content based on the provided content int fileSize = FILE_SIZE + (301_457 * fileCount); StringBuilder sb = new StringBuilder(fileSize); int index = 0; while (sb.length() < fileSize) { index++; sb.append("b_").append(index).append(": ").append(content).append('\n'); } Files.write(file, sb.toString().getBytes(), CREATE); }
From source file:org.fim.internal.StateManagerTest.java
@Test public void weCanRetrieveLastStateNumberWhenAStateFileIsMissing() throws IOException { s = s.addFiles("file_1", "file_2"); cut.createNewState(s);// www.ja va 2 s . c o m s = s.addFiles("file_3"); cut.createNewState(s); assertThat(cut.getLastStateNumber()).isEqualTo(2); Files.delete(cut.getStateFile(2)); assertThat(cut.getLastStateNumber()).isEqualTo(1); }
From source file:com.yahoo.bard.webservice.util.Utils.java
/** * Delete files or directories in the specified path. * * @param path The pathname/*from www .j a v a 2 s . c o m*/ */ public static void deleteFiles(String path) { Path directory = Paths.get(path); 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 { Files.delete(dir); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.kakao.hbase.manager.command.ExportKeysTest.java
@Test public void testRun() throws Exception { String outputFile = "exportkeys_test.keys"; try {// w w w .j a v a2 s . co m byte[] splitPoint = "splitpoint".getBytes(); splitTable(splitPoint); String[] argsParam = { "zookeeper", tableName, outputFile }; Args args = new ManagerArgs(argsParam); assertEquals("zookeeper", args.getZookeeperQuorum()); ExportKeys command = new ExportKeys(admin, args); waitForSplitting(2); command.run(); int i = 0; List<Triple<String, String, String>> results = new ArrayList<>(); for (String keys : Files.readAllLines(Paths.get(outputFile), Constant.CHARSET)) { i++; String[] split = keys.split(ExportKeys.DELIMITER); results.add(new ImmutableTriple<>(split[0], split[1], split[2])); } assertEquals(2, i); assertEquals(tableName, results.get(0).getLeft().trim()); assertArrayEquals("".getBytes(), Bytes.toBytesBinary(results.get(0).getMiddle().trim())); assertArrayEquals(splitPoint, Bytes.toBytesBinary(results.get(0).getRight().trim())); assertEquals(tableName, results.get(1).getLeft().trim()); assertArrayEquals(splitPoint, Bytes.toBytesBinary(results.get(1).getMiddle().trim())); assertArrayEquals("".getBytes(), Bytes.toBytesBinary(results.get(1).getRight().trim())); // split once more byte[] splitPoint2 = Bytes.toBytes(100L); splitTable(splitPoint2); command.run(); i = 0; results.clear(); for (String keys : Files.readAllLines(Paths.get(outputFile), Constant.CHARSET)) { i++; String[] split = keys.split(ExportKeys.DELIMITER); results.add(new ImmutableTriple<>(split[0], split[1], split[2])); } assertEquals(3, i); assertEquals(tableName, results.get(0).getLeft().trim()); assertArrayEquals("".getBytes(), Bytes.toBytesBinary(results.get(0).getMiddle().trim())); assertArrayEquals(splitPoint2, Bytes.toBytesBinary(results.get(0).getRight().trim())); assertEquals(tableName, results.get(1).getLeft().trim()); assertArrayEquals(splitPoint2, Bytes.toBytesBinary(results.get(1).getMiddle().trim())); assertArrayEquals(splitPoint, Bytes.toBytesBinary(results.get(1).getRight().trim())); assertEquals(tableName, results.get(2).getLeft().trim()); assertArrayEquals(splitPoint, Bytes.toBytesBinary(results.get(2).getMiddle().trim())); assertArrayEquals("".getBytes(), Bytes.toBytesBinary(results.get(2).getRight().trim())); } finally { Files.delete(Paths.get(outputFile)); } }
From source file:org.jhub1.agent.file.FileProcessorImpl.java
private boolean deleteFile(File file) { log.info("Delete file: " + filePath(file)); Path filePath = Paths.get(filePath(file)); try {// w w w . j a v a 2s . co m Files.delete(filePath); } catch (NoSuchFileException x) { return false; } catch (DirectoryNotEmptyException x) { return false; } catch (IOException x) { return false; } return true; }
From source file:org.jboss.as.test.integration.logging.handlers.SocketHandlerTestCase.java
@AfterClass public static void tearDown() throws Exception { undeploy(DEPLOYMENT_NAME);// w w w . java 2 s.co m // Clear the temporary directory and delete it Files.walkFileTree(TEMP_DIR, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); Files.deleteIfExists(TEMP_DIR); }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.util.VFSZipperZIPTest.java
@Test public void testZipUnzipZipUnzip() throws IOException, InterruptedException { Path pathToZip = temporaryPath; Path resultPath = outputPath; createFileHierarchy(temporaryPath);//from www.j av a 2 s . c om for (int i = 0; i < 2; i++) { testZip(pathToZip); assertZipWithFileHierarchy(archivePath); testUnzip(resultPath); assertUnzippedFileHierarchy(resultPath); pathToZip = resultPath; resultPath = temporaryPath.resolve("output" + (i + 1)); Files.delete(archivePath); } }