Class FileID
java.lang.Object
org.eclipse.jetty.util.FileID
Simple, yet surprisingly common utility methods for identifying various file types commonly seen and worked with in a
deployment scenario.
- 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetBasename(String filename) Retrieve the basename of a path.static StringgetBasename(Path path) Retrieve the basename of a path.static StringgetExtension(String filename) Retrieve the extension of a file path (not a directory).static StringgetExtension(URI uri) Retrieve the extension of a URI path.static StringgetExtension(Path path) Retrieve the extension of a file path (not a directory).static StringgetFileName(String path) Get the last segment of a String path returning it as the filenamestatic StringgetFileName(URI uri) Get the last segment of the URI returning it as the filenamestatic booleanhasNamedPathSegment(Path path, String segmentName) Does the provided path have a directory segment with the given name.static booleanTest if filename is any supported Java Archive type (ends injar,war, orzip).static booleanTest if URI is any supported Java Archive type.static booleanTest if Path is any supported Java Archive type (ends injar,war, orzip).static booleanisClassFile(String filename) Predicate to test for class filesstatic booleanisClassFile(Path path) Predicate to test for class filesstatic booleanisExtension(String filename, String... extensions) Test if filename matches any of the indicated extensions.static booleanisExtension(URI uri, String... extensions) Test if URI matches any of the indicated extensions.static booleanisExtension(Path path, String... extensions) Test if Path matches any of the indicated extensions.static booleanPredicate useful forStream<Path>to exclude hidden paths following filesystem rules for hidden directories and files.static booleanPredicate useful forStream<Path>to exclude hidden paths following filesystem rules for hidden directories and files.static booleanisJavaArchive(String filename) Is the filename a JAR file.static booleanisJavaArchive(URI uri) Is the URI pointing to a Java Archive (JAR) File (not directory)static booleanisJavaArchive(Path path) Is the path a Java Archive (JAR) File (not directory)static booleanisLibArchive(String filename) Test if filename is any supported Java Library Archive type (suitable to use as a library in a classpath/classloader)static booleanisLibArchive(URI uri) Test if URI is any supported Java Library Archive type (suitable to use as a library in a classpath/classloader)static booleanisLibArchive(Path path) Test if Path is any supported Java Library Archive type (suitable to use as a library in a classpath/classloader)static booleanisMetaInfVersions(Path path) Predicate to filter onMETA-INF/versions/*tree in walk/stream results.static booleanisModuleInfoClass(Path path) Predicate to skipmodule-info.classfiles.static booleanisNotMetaInfVersions(Path path) Predicate to skipMETA-INF/versions/*tree from walk/stream results.static booleanisNotModuleInfoClass(Path path) Predicate to skipmodule-info.classfiles.static booleanIs the path a TLD Filestatic booleanisWebArchive(String filename) Is the filename a WAR file.static booleanisWebArchive(URI uri) Is the path a Web Archive File (not directory)static booleanisWebArchive(Path path) Is the path a Web Archive File (not directory)static booleanIs the Path a file that ends in XML?static booleanIs the Path a file that ends in XML? 
- 
Constructor Details
- 
FileID
public FileID() 
 - 
 - 
Method Details
- 
getBasename
 - 
getBasename
 - 
getFileName
 - 
getFileName
 - 
getExtension
Retrieve the extension of a URI path.
This is the name of the last segment of the URI path with a substring for the extension (if any), excluding the dot, lower-cased.
"foo.tar.gz" "gz" "foo.bar" "bar" "foo." "" "foo" null ".bar" null null null- Parameters:
 uri- The URI to search- Returns:
 - The last segment extension. Null if input uri is null, or scheme is null, or URI is not a `jar:file:` or `file:` based URI
 
 - 
getExtension
Retrieve the extension of a file path (not a directory).
This is the name of the last segment of the file path with a substring for the extension (if any), excluding the dot, lower-cased.
"foo.tar.gz" "gz" "foo.bar" "bar" "foo." "" "foo" null ".bar" null null null- Parameters:
 path- The string path- Returns:
 - The last segment extension, or null if not a file, or null if there is no extension present
 
 - 
getExtension
Retrieve the extension of a file path (not a directory). This is the extension of filename of the last segment of the file path with a substring for the extension (if any), including the dot, lower-cased.- Parameters:
 filename- The string path- Returns:
 - The last segment extension excluding the leading dot; or null if not a file; or null if there is no extension present
 
 - 
isExtension
Test if Path matches any of the indicated extensions.- Parameters:
 path- the Path to testextensions- the list of extensions (all lowercase, without preceding.dot)- Returns:
 - true if Path is a file, and has an extension, and it matches any of the indicated extensions
 
 - 
isExtension
Test if URI matches any of the indicated extensions.- Parameters:
 uri- the URI to testextensions- the list of extensions (all lowercase, without preceding.dot)- Returns:
 - true if URI has an extension, and it matches any of the indicated extensions
 
 - 
isExtension
Test if filename matches any of the indicated extensions.- Parameters:
 filename- the filename to testextensions- the list of extensions (all lowercase, without preceding.dot)- Returns:
 - true if filename has an extension, and it matches any of the indicated extensions
 
 - 
hasNamedPathSegment
Does the provided path have a directory segment with the given name.- Parameters:
 path- the path to searchsegmentName- the segment name (of the given path) to look for (case-insensitive lookup), only capable of searching 1 segment name at a time, does not support "foo/bar" multi-segment names.- Returns:
 - true if the directory name exists in path, false if otherwise
 
 - 
isArchive
Test if Path is any supported Java Archive type (ends injar,war, orzip).- Parameters:
 path- the path to test- Returns:
 - true if path is a file, and an extension of 
jar,war, orzip - See Also:
 
 - 
isArchive
Test if filename is any supported Java Archive type (ends injar,war, orzip).- Parameters:
 filename- the filename to test- Returns:
 - true if path is a file and name ends with 
jar,war, orzip - See Also:
 
 - 
isArchive
Test if URI is any supported Java Archive type.- Parameters:
 uri- the URI to test- Returns:
 - true if the URI has a path that seems to point to a (
jar,war, orzip). - See Also:
 
 - 
isLibArchive
Test if Path is any supported Java Library Archive type (suitable to use as a library in a classpath/classloader)- Parameters:
 path- the path to test- Returns:
 - true if path is a file, and an extension of 
jar, orzip - See Also:
 
 - 
isLibArchive
Test if filename is any supported Java Library Archive type (suitable to use as a library in a classpath/classloader)- Parameters:
 filename- the filename to test- Returns:
 - true if path is a file and name ends with 
jar, orzip - See Also:
 
 - 
isLibArchive
Test if URI is any supported Java Library Archive type (suitable to use as a library in a classpath/classloader)- Parameters:
 uri- the URI to test- Returns:
 - true if the URI has a path that seems to point to a (
jar, orzip). - See Also:
 
 - 
isClassFile
Predicate to test for class files- Parameters:
 path- the path to test- Returns:
 - true if the filename ends with 
.class 
 - 
isClassFile
Predicate to test for class files- Parameters:
 filename- the filename to test- Returns:
 - true if the filename ends with 
.class 
 - 
isHidden
Predicate useful forStream<Path>to exclude hidden paths following filesystem rules for hidden directories and files.- Parameters:
 path- the possibly relative path to evaluate- Returns:
 - true if hidden by FileSystem rules, false if not
 - See Also:
 
 - 
isHidden
Predicate useful forStream<Path>to exclude hidden paths following filesystem rules for hidden directories and files.- Parameters:
 base- the base path to search from (anything above this path is not evaluated)path- the path to evaluate- Returns:
 - true if hidden by FileSystem rules, false if not
 - See Also:
 
 - 
isJavaArchive
Is the URI pointing to a Java Archive (JAR) File (not directory)- Parameters:
 uri- the uri to test.- Returns:
 - True if a jar file.
 
 - 
isJavaArchive
Is the path a Java Archive (JAR) File (not directory)- Parameters:
 path- the path to test.- Returns:
 - True if a jar file.
 
 - 
isJavaArchive
Is the filename a JAR file.- Parameters:
 filename- the filename to test.- Returns:
 - True if a jar file.
 
 - 
isMetaInfVersions
Predicate to filter onMETA-INF/versions/*tree in walk/stream results.This only works with a zipfs based FileSystem
- Parameters:
 path- the path to test- Returns:
 - true if path is in 
META-INF/versions/*tree 
 - 
isNotMetaInfVersions
Predicate to skipMETA-INF/versions/*tree from walk/stream results.This only works with a zipfs based FileSystem
- Parameters:
 path- the path to test- Returns:
 - true if not in 
META-INF/versions/*tree 
 - 
isModuleInfoClass
Predicate to skipmodule-info.classfiles.This is a simple test against the last path segment using
Path.getFileName()- Parameters:
 path- the path to test- Returns:
 - true if not a 
module-info.classfile 
 - 
isNotModuleInfoClass
Predicate to skipmodule-info.classfiles.This is a simple test against the last path segment using
Path.getFileName()- Parameters:
 path- the path to test- Returns:
 - true if not a 
module-info.classfile 
 - 
isTld
Is the path a TLD File- Parameters:
 path- the path to test.- Returns:
 - True if a .tld file.
 
 - 
isWebArchive
Is the path a Web Archive File (not directory)- Parameters:
 path- the path to test.- Returns:
 - True if a war file.
 
 - 
isWebArchive
Is the path a Web Archive File (not directory)- Parameters:
 uri- the uri to test.- Returns:
 - True if a war file.
 
 - 
isWebArchive
Is the filename a WAR file.- Parameters:
 filename- the filename to test.- Returns:
 - True if a war file.
 
 - 
isXml
Is the Path a file that ends in XML?- Parameters:
 path- the path to test- Returns:
 - true if a xml, false otherwise
 
 - 
isXml
Is the Path a file that ends in XML?- Parameters:
 filename- the filename to test- Returns:
 - true if a xml, false otherwise
 
 
 -