@Test public void checkFindFiles() throws IOException { File f = File.createTempFile("MyPrefix", ".remove-me", path.toFile()); f.deleteOnExit(); try { TempFileWarningLogger warner = new TempFileWarningLogger( log, "MyPrefix*", new String[] { "temp", "remove-me", "~notrequired" }, path); boolean found = warner.checkFiles(); assertTrue("Should have found matching files", found); verify(log, never()).warn(anyString()); } finally { f.delete(); } }
@SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") public boolean checkFiles() { if (log.isDebugEnabled()) { log.debug("Looking for temp files matching " + glob + " in directory " + dir); } try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir, glob)) { for (Path file : stream) { if (log.isDebugEnabled()) { log.debug("Solr suggester temp file found matching file pattern: " + glob + ", path: " + file); log.debug("Removing suggester temp files."); } return true; } return false; } catch (IOException e) { throw new RuntimeException("Unable to create directory stream", e); } }
TempFileWarningLogger { @SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") public boolean checkFiles() { if (log.isDebugEnabled()) { log.debug("Looking for temp files matching " + glob + " in directory " + dir); } try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir, glob)) { for (Path file : stream) { if (log.isDebugEnabled()) { log.debug("Solr suggester temp file found matching file pattern: " + glob + ", path: " + file); log.debug("Removing suggester temp files."); } return true; } return false; } catch (IOException e) { throw new RuntimeException("Unable to create directory stream", e); } } }
TempFileWarningLogger { @SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") public boolean checkFiles() { if (log.isDebugEnabled()) { log.debug("Looking for temp files matching " + glob + " in directory " + dir); } try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir, glob)) { for (Path file : stream) { if (log.isDebugEnabled()) { log.debug("Solr suggester temp file found matching file pattern: " + glob + ", path: " + file); log.debug("Removing suggester temp files."); } return true; } return false; } catch (IOException e) { throw new RuntimeException("Unable to create directory stream", e); } } TempFileWarningLogger(Logger log, String prefix, String[] extensions, Path dir); }
TempFileWarningLogger { @SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") public boolean checkFiles() { if (log.isDebugEnabled()) { log.debug("Looking for temp files matching " + glob + " in directory " + dir); } try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir, glob)) { for (Path file : stream) { if (log.isDebugEnabled()) { log.debug("Solr suggester temp file found matching file pattern: " + glob + ", path: " + file); log.debug("Removing suggester temp files."); } return true; } return false; } catch (IOException e) { throw new RuntimeException("Unable to create directory stream", e); } } TempFileWarningLogger(Logger log, String prefix, String[] extensions, Path dir); @SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") boolean checkFiles(); @SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") void removeFiles(); }
TempFileWarningLogger { @SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") public boolean checkFiles() { if (log.isDebugEnabled()) { log.debug("Looking for temp files matching " + glob + " in directory " + dir); } try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir, glob)) { for (Path file : stream) { if (log.isDebugEnabled()) { log.debug("Solr suggester temp file found matching file pattern: " + glob + ", path: " + file); log.debug("Removing suggester temp files."); } return true; } return false; } catch (IOException e) { throw new RuntimeException("Unable to create directory stream", e); } } TempFileWarningLogger(Logger log, String prefix, String[] extensions, Path dir); @SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") boolean checkFiles(); @SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") void removeFiles();  }