Package org.reflections.vfs
Class Vfs
- java.lang.Object
-
- org.reflections.vfs.Vfs
-
public abstract class Vfs extends java.lang.Objecta simple virtual file system bridgeuse the
fromURL(java.net.URL)to get aVfs.Dir, then useVfs.Dir.getFiles()to iterate over theVfs.Filefor example:
Vfs.Dir dir = Vfs.fromURL(url); Iterablefiles = dir.getFiles(); for (Vfs.File file : files) { InputStream is = file.openInputStream(); } fromURL(java.net.URL)uses staticVfs.DefaultUrlTypesto 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.UrlTypeusingaddDefaultURLTypes(org.reflections.vfs.Vfs.UrlType)orsetDefaultURLTypes(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 Classes Modifier and Type Class Description static classVfs.DefaultUrlTypesdefault url types used byfromURL(java.net.URL)static interfaceVfs.Diran abstract vfs dirstatic interfaceVfs.Filean abstract vfs filestatic interfaceVfs.UrlTypea matcher and factory for a url
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<Vfs.UrlType>defaultUrlTypes
-
Constructor Summary
Constructors Constructor Description Vfs()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddDefaultURLTypes(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, java.lang.String packagePrefix, java.util.function.Predicate<java.lang.String> nameFilter)return an iterable of allVfs.Filein given urls, starting with given packagePrefix and matching nameFilterstatic java.lang.Iterable<Vfs.File>findFiles(java.util.Collection<java.net.URL> urls, java.util.function.Predicate<Vfs.File> filePredicate)return an iterable of allVfs.Filein given urls, matching filePredicatestatic Vfs.DirfromURL(java.net.URL url)tries to create a Dir from the given url, using the defaultUrlTypesstatic Vfs.DirfromURL(java.net.URL url, java.util.List<Vfs.UrlType> urlTypes)tries to create a Dir from the given url, using the given urlTypesstatic Vfs.DirfromURL(java.net.URL url, Vfs.UrlType... urlTypes)tries to create a Dir from the given url, using the given urlTypesstatic java.util.List<Vfs.UrlType>getDefaultUrlTypes()the default url types that will be used when issuingfromURL(java.net.URL)static java.io.FilegetFile(java.net.URL url)try to getFilefrom urlprivate static booleanhasInnerJarFileInPath(java.net.URL url)private static booleanhasJarFileInPath(java.net.URL url)static voidsetDefaultURLTypes(java.util.List<Vfs.UrlType> urlTypes)sets the static default url types.
-
-
-
Field Detail
-
defaultUrlTypes
private static java.util.List<Vfs.UrlType> defaultUrlTypes
-
-
Method Detail
-
getDefaultUrlTypes
public static java.util.List<Vfs.UrlType> getDefaultUrlTypes()
the default url types that will be used when issuingfromURL(java.net.URL)
-
setDefaultURLTypes
public static void setDefaultURLTypes(java.util.List<Vfs.UrlType> urlTypes)
sets the static default url types. can be used to statically plug in urlTypes
-
addDefaultURLTypes
public static void addDefaultURLTypes(Vfs.UrlType urlType)
add a static default url types to the beginning of the default url types list. can be used to statically plug in urlTypes
-
fromURL
public static Vfs.Dir fromURL(java.net.URL url)
tries to create a Dir from the given url, using the defaultUrlTypes
-
fromURL
public 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
-
fromURL
public static Vfs.Dir fromURL(java.net.URL url, Vfs.UrlType... urlTypes)
tries to create a Dir from the given url, using the given urlTypes
-
findFiles
public static java.lang.Iterable<Vfs.File> findFiles(java.util.Collection<java.net.URL> inUrls, java.lang.String packagePrefix, java.util.function.Predicate<java.lang.String> nameFilter)
return an iterable of allVfs.Filein given urls, starting with given packagePrefix and matching nameFilter
-
findFiles
public static java.lang.Iterable<Vfs.File> findFiles(java.util.Collection<java.net.URL> urls, java.util.function.Predicate<Vfs.File> filePredicate)
return an iterable of allVfs.Filein given urls, matching filePredicate
-
getFile
public static java.io.File getFile(java.net.URL url)
try to getFilefrom url
-
hasJarFileInPath
private static boolean hasJarFileInPath(java.net.URL url)
-
hasInnerJarFileInPath
private static boolean hasInnerJarFileInPath(java.net.URL url)
-
-