@Test public void testMissingJarFileReturnsGracefully() { ResourceList rl = new ResourceList("foo"); File missingFile = new File("abracadabraphoenix.txt"); assertFalse("Did not expect a fake test file to actually exist", missingFile.exists()); assertEquals(Collections.emptyList(), rl.getResourcesFromJarFile(missingFile, Pattern.compile("pattern"))); }
Collection<String> getResourcesFromJarFile( final File file, final Pattern pattern) { final List<String> retVal = new ArrayList<>(); ZipFile zf; try { zf = new ZipFile(file); } catch (FileNotFoundException|NoSuchFileException e) { return Collections.emptyList(); } catch (final ZipException e) { throw new Error(e); } catch (final IOException e) { throw new Error(e); } final Enumeration e = zf.entries(); while (e.hasMoreElements()) { final ZipEntry ze = (ZipEntry) e.nextElement(); final String fileName = ze.getName(); final boolean accept = pattern.matcher(fileName).matches(); LOGGER.trace("fileName:" + fileName); LOGGER.trace("File:" + file.toString()); LOGGER.trace("Match:" + accept); if (accept) { LOGGER.trace("Adding File from Jar: " + fileName); retVal.add("/" + fileName); } } try { zf.close(); } catch (final IOException e1) { throw new Error(e1); } return retVal; }
ResourceList { Collection<String> getResourcesFromJarFile( final File file, final Pattern pattern) { final List<String> retVal = new ArrayList<>(); ZipFile zf; try { zf = new ZipFile(file); } catch (FileNotFoundException|NoSuchFileException e) { return Collections.emptyList(); } catch (final ZipException e) { throw new Error(e); } catch (final IOException e) { throw new Error(e); } final Enumeration e = zf.entries(); while (e.hasMoreElements()) { final ZipEntry ze = (ZipEntry) e.nextElement(); final String fileName = ze.getName(); final boolean accept = pattern.matcher(fileName).matches(); LOGGER.trace("fileName:" + fileName); LOGGER.trace("File:" + file.toString()); LOGGER.trace("Match:" + accept); if (accept) { LOGGER.trace("Adding File from Jar: " + fileName); retVal.add("/" + fileName); } } try { zf.close(); } catch (final IOException e1) { throw new Error(e1); } return retVal; } }
ResourceList { Collection<String> getResourcesFromJarFile( final File file, final Pattern pattern) { final List<String> retVal = new ArrayList<>(); ZipFile zf; try { zf = new ZipFile(file); } catch (FileNotFoundException|NoSuchFileException e) { return Collections.emptyList(); } catch (final ZipException e) { throw new Error(e); } catch (final IOException e) { throw new Error(e); } final Enumeration e = zf.entries(); while (e.hasMoreElements()) { final ZipEntry ze = (ZipEntry) e.nextElement(); final String fileName = ze.getName(); final boolean accept = pattern.matcher(fileName).matches(); LOGGER.trace("fileName:" + fileName); LOGGER.trace("File:" + file.toString()); LOGGER.trace("Match:" + accept); if (accept) { LOGGER.trace("Adding File from Jar: " + fileName); retVal.add("/" + fileName); } } try { zf.close(); } catch (final IOException e1) { throw new Error(e1); } return retVal; } ResourceList(String rootResourceDir); }
ResourceList { Collection<String> getResourcesFromJarFile( final File file, final Pattern pattern) { final List<String> retVal = new ArrayList<>(); ZipFile zf; try { zf = new ZipFile(file); } catch (FileNotFoundException|NoSuchFileException e) { return Collections.emptyList(); } catch (final ZipException e) { throw new Error(e); } catch (final IOException e) { throw new Error(e); } final Enumeration e = zf.entries(); while (e.hasMoreElements()) { final ZipEntry ze = (ZipEntry) e.nextElement(); final String fileName = ze.getName(); final boolean accept = pattern.matcher(fileName).matches(); LOGGER.trace("fileName:" + fileName); LOGGER.trace("File:" + file.toString()); LOGGER.trace("Match:" + accept); if (accept) { LOGGER.trace("Adding File from Jar: " + fileName); retVal.add("/" + fileName); } } try { zf.close(); } catch (final IOException e1) { throw new Error(e1); } return retVal; } ResourceList(String rootResourceDir); Collection<Path> getResourceList(final String pattern); }
ResourceList { Collection<String> getResourcesFromJarFile( final File file, final Pattern pattern) { final List<String> retVal = new ArrayList<>(); ZipFile zf; try { zf = new ZipFile(file); } catch (FileNotFoundException|NoSuchFileException e) { return Collections.emptyList(); } catch (final ZipException e) { throw new Error(e); } catch (final IOException e) { throw new Error(e); } final Enumeration e = zf.entries(); while (e.hasMoreElements()) { final ZipEntry ze = (ZipEntry) e.nextElement(); final String fileName = ze.getName(); final boolean accept = pattern.matcher(fileName).matches(); LOGGER.trace("fileName:" + fileName); LOGGER.trace("File:" + file.toString()); LOGGER.trace("Match:" + accept); if (accept) { LOGGER.trace("Adding File from Jar: " + fileName); retVal.add("/" + fileName); } } try { zf.close(); } catch (final IOException e1) { throw new Error(e1); } return retVal; } ResourceList(String rootResourceDir); Collection<Path> getResourceList(final String pattern);  }