public URL nextElement() { if ( hasMoreElements() ) { // initialized by hasMoreElements() final String name = nextEntryName; nextEntryName = null; try { return findResource( name ); } catch ( final MalformedURLException e ) { // this shouldn't happen, hence illegal state throw new IllegalStateException( e.toString() ); } } throw new NoSuchElementException(); }
/** * Returns the appropriate {@link Iterator} to iterate over the contents of the given URL. * * @param url The containing URL * @return Iterator that iterates over resources contained inside the given URL */ private Iterator<String> scan( final URL url ) { isFolder = url.getPath().endsWith( "/" ); if ( globber == GlobberStrategy.EXACT && !recurse ) { try { // short-cut the nextElement() process nextEntryName = subPath + globPattern; // but still need to check resource actually exists! Streams.open( findResource( nextEntryName ) ).close(); } catch ( final Exception e ) // IOException + SecurityException + etc... { nextEntryName = null; } return NO_ENTRIES; } return isFolder ? new FileEntryIterator( url, subPath, recurse ) : new ZipEntryIterator( url ); }