ClasspathResourceFinder { public ImmutableList<ResourceReference> findResources(String regex ) throws IOException { return findResources( Pattern.compile( regex ) ); } private  ClasspathResourceFinder(long maxJarFileSize, boolean ignoreBrokenJarFiles); ImmutableList<ResourceReference> findResources(String regex ); ImmutableList<ResourceReference> findResources(Pattern pattern );  }
@Test public void testGetResources() throws Exception { ClasspathResourceFinder classpathResourceFinder = new ClasspathResourceFinder.Builder().build(); Collection<ResourceReference> resources = classpathResourceFinder.findResources( Pattern.compile( ".*/resource_finder/.*\\.txt" ) ); System.out.printf( "%s\n", CollectionFormatter.table( resources ) ); }
@Test public void testClasspathResourcesFinder2() throws Exception { ClasspathResourceFinder classpathResourceFinder = new ClasspathResourceFinder.Builder().build(); Collection<ResourceReference> resources = classpathResourceFinder.findResources( Pattern.compile( ".*\\.txt" ) ); for (ResourceReference resource : resources) { try( InputStream inputStream = resource.open() ) { ByteStreams.toByteArray( inputStream ); } } System.out.printf( "%s\n", CollectionFormatter.table( resources ) ); }
@Test public void testGetClasspathResourceSpecific() throws Exception { System.out.printf( "%s\n", System.getProperty( "java.class.path" ) ); ClasspathResourceFinder classpathResourceFinder = new ClasspathResourceFinder.Builder().build(); Collection<ResourceReference> resources = classpathResourceFinder.findResources( Pattern.compile( "testing/.*\\.txt" ) ); ImmutableList<String> paths = ClasspathResources.toPaths( resources ); System.out.printf( "%s\n", CollectionFormatter.table( resources ) ); assertThat( paths, hasItem( "testing/first.txt" ) ); assertThat( paths, hasItem( "testing/fakedir/second.txt" ) ); assertThat( paths, hasItem( "testing/fakedir/nested/third.txt" ) ); for (ResourceReference resource : resources) { try( InputStream inputStream = resource.open() ) { ByteStreams.toByteArray( inputStream ); } } }