HerdFileUtils extends FileUtils { public static void deleteDirectoryIgnoreException(File directory) { try { FileUtils.deleteDirectory(directory); } catch (Exception e) { LOGGER.warn(String.format("Failed to delete \"%s\" directory.", directory), e); } }  static void verifyFileExistsAndReadable(File file); static void cleanDirectoryIgnoreException(File directory); static void deleteDirectoryIgnoreException(File directory); static void deleteFileIgnoreException(File file); static final long BYTES_PER_GB; }
@Test public void testDeleteDirectoryIgnoreException() throws IOException { File testFile = createLocalFile(localTempPath.toString(), "SOME_FILE", FILE_SIZE_1_KB); HerdFileUtils.deleteDirectoryIgnoreException(localTempPath.toFile()); assertFalse(testFile.exists()); assertFalse(localTempPath.toFile().exists()); }
@Test public void testDeleteDirectoryIgnoreExceptionWithException() throws Exception { final File testFile = createLocalFile(localTempPath.toString(), "SOME_FILE", FILE_SIZE_1_KB); executeWithoutLogging(HerdFileUtils.class, new Command() { @Override public void execute() throws Exception { HerdFileUtils.deleteDirectoryIgnoreException(testFile); } }); assertTrue(testFile.exists()); }
@Test public void testDeleteFileIgnoreExceptionWithException() throws Exception { executeWithoutLogging(HerdFileUtils.class, new Command() { @Override public void execute() throws Exception { HerdFileUtils.deleteDirectoryIgnoreException(new File("I_DO_NOT_EXIST")); } }); }