@Test public void deleteDirectoryQuietlyWhenNotExistent() { String dirname = "build/d-test"; File dir = new File(dirname); assertFalse(dir.exists()); FileSystemUtil.deleteDirectoryQuietly(dirname); assertFalse(dir.exists()); }
public static void deleteDirectoryQuietly(String rootDirName) { File rootDir = new File(rootDirName); if (rootDir.exists()) { try (Stream<Path> paths = java.nio.file.Files.walk(rootDir.toPath())) { paths.sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } catch (IOException e) { LOGGER.error("Can't delete directory {}: ", rootDirName, e); } } }
FileSystemUtil { public static void deleteDirectoryQuietly(String rootDirName) { File rootDir = new File(rootDirName); if (rootDir.exists()) { try (Stream<Path> paths = java.nio.file.Files.walk(rootDir.toPath())) { paths.sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } catch (IOException e) { LOGGER.error("Can't delete directory {}: ", rootDirName, e); } } } }
FileSystemUtil { public static void deleteDirectoryQuietly(String rootDirName) { File rootDir = new File(rootDirName); if (rootDir.exists()) { try (Stream<Path> paths = java.nio.file.Files.walk(rootDir.toPath())) { paths.sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } catch (IOException e) { LOGGER.error("Can't delete directory {}: ", rootDirName, e); } } } private  FileSystemUtil(); }
FileSystemUtil { public static void deleteDirectoryQuietly(String rootDirName) { File rootDir = new File(rootDirName); if (rootDir.exists()) { try (Stream<Path> paths = java.nio.file.Files.walk(rootDir.toPath())) { paths.sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } catch (IOException e) { LOGGER.error("Can't delete directory {}: ", rootDirName, e); } } } private  FileSystemUtil(); static boolean checkFileOrResourceExists(String filename); static void assertFileOrResourceExists(String filename); static String readFileAsText(String filename); static String readFileAsText(String fileName, String alternateDir); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static void writeStringToFile(String content, String filename); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static void appendStringToFile(String content, String filename); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static byte[] readBytesFromFile(String filename); static void deleteDirectoryQuietly(String rootDirName); }
FileSystemUtil { public static void deleteDirectoryQuietly(String rootDirName) { File rootDir = new File(rootDirName); if (rootDir.exists()) { try (Stream<Path> paths = java.nio.file.Files.walk(rootDir.toPath())) { paths.sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } catch (IOException e) { LOGGER.error("Can't delete directory {}: ", rootDirName, e); } } } private  FileSystemUtil(); static boolean checkFileOrResourceExists(String filename); static void assertFileOrResourceExists(String filename); static String readFileAsText(String filename); static String readFileAsText(String fileName, String alternateDir); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static void writeStringToFile(String content, String filename); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static void appendStringToFile(String content, String filename); @SuppressWarnings("squid:S1166") // wants log or rethrow exception. It's logged well enough here. static byte[] readBytesFromFile(String filename); static void deleteDirectoryQuietly(String rootDirName); static final String CLASSPATH_PREFIX; }