- java.lang.Object
-
- org.scijava.common3.URLs
-
public final class URLs extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Collection<URL>appendContents(Collection<URL> result, URL directory)Recursively adds contents from the referenced directory to an existing collection.static Collection<URL>appendContents(Collection<URL> result, URL directory, boolean recurse, boolean filesOnly)Add contents from the referenced directory to an existing collection.static Collection<URL>listContents(URL directory)Recursively lists the contents of the referenced directory.static Collection<URL>listContents(URL directory, boolean recurse, boolean filesOnly)Lists all contents of the referenced directory.static FiletoFile(String url)Converts the given URL string to its correspondingFile.static FiletoFile(URL url)
-
-
-
Method Detail
-
listContents
public static Collection<URL> listContents(URL directory)
Recursively lists the contents of the referenced directory. Directories are excluded from the result. Supported protocols includefileandjar.- Parameters:
directory- The directory whose contents should be listed.- Returns:
- A collection of
URLs representing the directory's contents. - See Also:
listContents(URL, boolean, boolean)
-
listContents
public static Collection<URL> listContents(URL directory, boolean recurse, boolean filesOnly)
Lists all contents of the referenced directory. Supported protocols includefileandjar.- Parameters:
directory- The directory whose contents should be listed.recurse- Whether to list contents recursively, as opposed to only the directory's direct contents.filesOnly- Whether to exclude directories in the resulting collection of contents.- Returns:
- A collection of
URLs representing the directory's contents.
-
appendContents
public static Collection<URL> appendContents(Collection<URL> result, URL directory)
Recursively adds contents from the referenced directory to an existing collection. Directories are excluded from the result. Supported protocols includefileandjar.- Parameters:
result- The collection to which contents should be added.directory- The directory whose contents should be listed.- Returns:
- A collection of
URLs representing the directory's contents. - See Also:
appendContents(Collection, URL, boolean, boolean)
-
appendContents
public static Collection<URL> appendContents(Collection<URL> result, URL directory, boolean recurse, boolean filesOnly)
Add contents from the referenced directory to an existing collection. Supported protocols includefileandjar.- Parameters:
result- The collection to which contents should be added.directory- The directory whose contents should be listed.recurse- Whether to append contents recursively, as opposed to only the directory's direct contents.filesOnly- Whether to exclude directories in the resulting collection of contents.- Returns:
- A collection of
URLs representing the directory's contents.
-
toFile
public static File toFile(URL url)
Converts the givenURLto its correspondingFile.This method is similar to calling
new File(url.toURI())except that it also handles "jar:file:" URLs, returning the path to the JAR file.- Parameters:
url- The URL to convert.- Returns:
- A file path suitable for use with e.g.
FileInputStream - Throws:
IllegalArgumentException- if the URL does not correspond to a file.
-
toFile
public static File toFile(String url)
Converts the given URL string to its correspondingFile.- Parameters:
url- The URL to convert.- Returns:
- A file path suitable for use with e.g.
FileInputStream - Throws:
IllegalArgumentException- if the URL does not correspond to a file.
-
-