public abstract class Vfs
extends java.lang.Object
use the fromURL(java.net.URL)
to get a Vfs.Dir
,
then use Vfs.Dir.getFiles()
to iterate over the Vfs.File
for example:
Vfs.Dir dir = Vfs.fromURL(url); Iterablefiles = dir.getFiles(); for (Vfs.File file : files) { InputStream is = file.openInputStream(); }
fromURL(java.net.URL)
uses static Vfs.DefaultUrlTypes
to resolve URLs.
It contains VfsTypes for handling for common resources such as local jar file, local directory, jar url, jar input stream and more.
It can be plugged in with other Vfs.UrlType
using addDefaultURLTypes(org.reflections.vfs.Vfs.UrlType)
or setDefaultURLTypes(java.util.List)
.
for example:
Vfs.addDefaultURLTypes(new Vfs.UrlType() { public boolean matches(URL url) { return url.getProtocol().equals("http"); } public Vfs.Dir createDir(final URL url) { return new HttpDir(url); //implement this type... (check out a naive implementation on VfsTest) } }); Vfs.Dir dir = Vfs.fromURL(new URL("http://mirrors.ibiblio.org/pub/mirrors/maven2/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6.jar"));
use findFiles(java.util.Collection, com.google.common.base.Predicate)
to get an
iteration of files matching given name predicate over given list of urls
Modifier and Type | Class and Description |
---|---|
static class |
Vfs.DefaultUrlTypes
default url types used by
fromURL(java.net.URL) |
static interface |
Vfs.Dir
an abstract vfs dir
|
static interface |
Vfs.File
an abstract vfs file
|
static interface |
Vfs.UrlType
a matcher and factory for a url
|
Modifier and Type | Field and Description |
---|---|
private static java.util.List<Vfs.UrlType> |
defaultUrlTypes |
Constructor and Description |
---|
Vfs() |
Modifier and Type | Method and Description |
---|---|
static void |
addDefaultURLTypes(Vfs.UrlType urlType)
add a static default url types to the beginning of the default url types list.
|
static java.lang.Iterable<Vfs.File> |
findFiles(java.util.Collection<java.net.URL> inUrls,
com.google.common.base.Predicate<Vfs.File> filePredicate)
return an iterable of all
Vfs.File in given urls, matching filePredicate |
static java.lang.Iterable<Vfs.File> |
findFiles(java.util.Collection<java.net.URL> inUrls,
java.lang.String packagePrefix,
com.google.common.base.Predicate<java.lang.String> nameFilter)
return an iterable of all
Vfs.File in given urls, starting with given packagePrefix and matching nameFilter |
static Vfs.Dir |
fromURL(java.net.URL url)
tries to create a Dir from the given url, using the defaultUrlTypes
|
static Vfs.Dir |
fromURL(java.net.URL url,
java.util.List<Vfs.UrlType> urlTypes)
tries to create a Dir from the given url, using the given urlTypes
|
static Vfs.Dir |
fromURL(java.net.URL url,
Vfs.UrlType... urlTypes)
tries to create a Dir from the given url, using the given urlTypes
|
static java.util.List<Vfs.UrlType> |
getDefaultUrlTypes()
the default url types that will be used when issuing
fromURL(java.net.URL) |
static java.io.File |
getFile(java.net.URL url)
try to get
File from url |
static void |
setDefaultURLTypes(java.util.List<Vfs.UrlType> urlTypes)
sets the static default url types.
|
private static java.util.List<Vfs.UrlType> defaultUrlTypes
public static java.util.List<Vfs.UrlType> getDefaultUrlTypes()
fromURL(java.net.URL)
public static void setDefaultURLTypes(java.util.List<Vfs.UrlType> urlTypes)
public static void addDefaultURLTypes(Vfs.UrlType urlType)
public static Vfs.Dir fromURL(java.net.URL url)
public static Vfs.Dir fromURL(java.net.URL url, java.util.List<Vfs.UrlType> urlTypes)
public static Vfs.Dir fromURL(java.net.URL url, Vfs.UrlType... urlTypes)
public static java.lang.Iterable<Vfs.File> findFiles(java.util.Collection<java.net.URL> inUrls, java.lang.String packagePrefix, com.google.common.base.Predicate<java.lang.String> nameFilter)
Vfs.File
in given urls, starting with given packagePrefix and matching nameFilterpublic static java.lang.Iterable<Vfs.File> findFiles(java.util.Collection<java.net.URL> inUrls, com.google.common.base.Predicate<Vfs.File> filePredicate)
Vfs.File
in given urls, matching filePredicate@Nullable public static java.io.File getFile(java.net.URL url)
File
from url