@Test public void testDeletePathIfEmpty() throws IOException { final FileSystem localFs = FileSystem.getLocalFileSystem(); final File dir = tmp.newFolder(); assertTrue(dir.exists()); final Path dirPath = new Path(dir.toURI()); assertTrue(FileUtils.deletePathIfEmpty(localFs, dirPath)); assertTrue(FileUtils.deletePathIfEmpty(localFs, dirPath)); final File nonEmptyDir = tmp.newFolder(); final Path nonEmptyDirPath = new Path(nonEmptyDir.toURI()); new FileOutputStream(new File(nonEmptyDir, "filename")).close(); assertFalse(FileUtils.deletePathIfEmpty(localFs, nonEmptyDirPath)); }
public static boolean deletePathIfEmpty(FileSystem fileSystem, Path path) throws IOException { final FileStatus[] fileStatuses; try { fileStatuses = fileSystem.listStatus(path); } catch (FileNotFoundException e) { return true; } catch (Exception e) { return false; } if (fileStatuses == null) { return true; } else if (fileStatuses.length == 0) { return fileSystem.delete(path, false); } else { return false; } }
FileUtils { public static boolean deletePathIfEmpty(FileSystem fileSystem, Path path) throws IOException { final FileStatus[] fileStatuses; try { fileStatuses = fileSystem.listStatus(path); } catch (FileNotFoundException e) { return true; } catch (Exception e) { return false; } if (fileStatuses == null) { return true; } else if (fileStatuses.length == 0) { return fileSystem.delete(path, false); } else { return false; } } }
FileUtils { public static boolean deletePathIfEmpty(FileSystem fileSystem, Path path) throws IOException { final FileStatus[] fileStatuses; try { fileStatuses = fileSystem.listStatus(path); } catch (FileNotFoundException e) { return true; } catch (Exception e) { return false; } if (fileStatuses == null) { return true; } else if (fileStatuses.length == 0) { return fileSystem.delete(path, false); } else { return false; } } private  FileUtils(); }
FileUtils { public static boolean deletePathIfEmpty(FileSystem fileSystem, Path path) throws IOException { final FileStatus[] fileStatuses; try { fileStatuses = fileSystem.listStatus(path); } catch (FileNotFoundException e) { return true; } catch (Exception e) { return false; } if (fileStatuses == null) { return true; } else if (fileStatuses.length == 0) { return fileSystem.delete(path, false); } else { return false; } } private  FileUtils(); static void writeCompletely(WritableByteChannel channel, ByteBuffer src); static String getRandomFilename(final String prefix); static String readFile(File file, String charsetName); static String readFileUtf8(File file); static void writeFile(File file, String contents, String encoding); static void writeFileUtf8(File file, String contents); static byte[] readAllBytes(java.nio.file.Path path); static void deleteFileOrDirectory(File file); static void deleteDirectory(File directory); static void deleteDirectoryQuietly(File directory); static void cleanDirectory(File directory); static boolean deletePathIfEmpty(FileSystem fileSystem, Path path); static void copy(Path sourcePath, Path targetPath, boolean executable); static Path compressDirectory(Path directory, Path target); static Path expandDirectory(Path file, Path targetDirectory); }
FileUtils { public static boolean deletePathIfEmpty(FileSystem fileSystem, Path path) throws IOException { final FileStatus[] fileStatuses; try { fileStatuses = fileSystem.listStatus(path); } catch (FileNotFoundException e) { return true; } catch (Exception e) { return false; } if (fileStatuses == null) { return true; } else if (fileStatuses.length == 0) { return fileSystem.delete(path, false); } else { return false; } } private  FileUtils(); static void writeCompletely(WritableByteChannel channel, ByteBuffer src); static String getRandomFilename(final String prefix); static String readFile(File file, String charsetName); static String readFileUtf8(File file); static void writeFile(File file, String contents, String encoding); static void writeFileUtf8(File file, String contents); static byte[] readAllBytes(java.nio.file.Path path); static void deleteFileOrDirectory(File file); static void deleteDirectory(File directory); static void deleteDirectoryQuietly(File directory); static void cleanDirectory(File directory); static boolean deletePathIfEmpty(FileSystem fileSystem, Path path); static void copy(Path sourcePath, Path targetPath, boolean executable); static Path compressDirectory(Path directory, Path target); static Path expandDirectory(Path file, Path targetDirectory);  }