Package org.reflections.vfs
Class Vfs
java.lang.Object
org.reflections.vfs.Vfs
a simple virtual file system bridge
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);
Iterableinvalid input: '<'Vfs.File> files = 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, java.util.function.Predicate) to get an
iteration of files matching given name predicate over given list of urls
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumdefault url types used byfromURL(java.net.URL)static interfacean abstract vfs dirstatic interfacean abstract vfs filestatic interfacea matcher and factory for a url -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddDefaultURLTypes(Vfs.UrlType urlType) add a static default url types to the beginning of the default url types list.return an iterable of allVfs.Filein given urls, starting with given packagePrefix and matching nameFilterfindFiles(Collection<URL> urls, Predicate<Vfs.File> filePredicate) return an iterable of allVfs.Filein given urls, matching filePredicatestatic Vfs.Dirtries to create a Dir from the given url, using the defaultUrlTypesstatic Vfs.DirfromURL(URL url, List<Vfs.UrlType> urlTypes) tries to create a Dir from the given url, using the given urlTypesstatic Vfs.DirfromURL(URL url, Vfs.UrlType... urlTypes) tries to create a Dir from the given url, using the given urlTypesstatic List<Vfs.UrlType> the default url types that will be used when issuingfromURL(java.net.URL)static Filetry to getFilefrom urlprivate static booleanhasJarFileInPath(URL url) static voidsetDefaultURLTypes(List<Vfs.UrlType> urlTypes) sets the static default url types.
-
Field Details
-
defaultUrlTypes
-
-
Constructor Details
-
Vfs
public Vfs()
-
-
Method Details
-
getDefaultUrlTypes
the default url types that will be used when issuingfromURL(java.net.URL) -
setDefaultURLTypes
sets the static default url types. can be used to statically plug in urlTypes -
addDefaultURLTypes
add a static default url types to the beginning of the default url types list. can be used to statically plug in urlTypes -
fromURL
tries to create a Dir from the given url, using the defaultUrlTypes -
fromURL
tries to create a Dir from the given url, using the given urlTypes -
fromURL
tries to create a Dir from the given url, using the given urlTypes -
findFiles
public static Iterable<Vfs.File> findFiles(Collection<URL> inUrls, String packagePrefix, Predicate<String> nameFilter) return an iterable of allVfs.Filein given urls, starting with given packagePrefix and matching nameFilter -
findFiles
return an iterable of allVfs.Filein given urls, matching filePredicate -
getFile
try to getFilefrom url -
hasJarFileInPath
-