Package org.eclipse.jetty.util
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
getBasename
(Path path) Retrieve the basename of a path.static String
getExtension
(String filename) Retrieve the extension of a file path (not a directory).static String
getExtension
(URI uri) Retrieve the extension of a URI path.static String
getExtension
(Path path) Retrieve the extension of a file path (not a directory).static String
getFileName
(String path) Get the last segment of a String path returning it as the filenamestatic String
getFileName
(URI uri) Get the last segment of the URI returning it as the filenamestatic boolean
hasNamedPathSegment
(Path path, String segmentName) Does the provided path have a directory segment with the given name.static boolean
Test if filename is any supported Java Archive type (ends injar
,war
, orzip
).static boolean
Test if URI is any supported Java Archive type.static boolean
Test if Path is any supported Java Archive type (ends injar
,war
, orzip
).static boolean
isClassFile
(Path path) Predicate to test for class filesstatic boolean
isExtension
(String filename, String... extensions) Test if filename matches any of the indicated extensions.static boolean
isExtension
(URI uri, String... extensions) Test if URI matches any of the indicated extensions.static boolean
isExtension
(Path path, String... extensions) Test if Path matches any of the indicated extensions.static boolean
Predicate useful forStream<Path>
to exclude hidden paths following filesystem rules for hidden directories and files.static boolean
Predicate useful forStream<Path>
to exclude hidden paths following filesystem rules for hidden directories and files.static boolean
isJavaArchive
(String filename) Is the filename a JAR file.static boolean
isJavaArchive
(URI uri) Is the URI pointing to a Java Archive (JAR) File (not directory)static boolean
isJavaArchive
(Path path) Is the path a Java Archive (JAR) File (not directory)static boolean
isLibArchive
(String filename) Test if filename is any supported Java Library Archive type (suitable to use as a library in a classpath/classloader)static boolean
isLibArchive
(URI uri) Test if URI is any supported Java Library Archive type (suitable to use as a library in a classpath/classloader)static boolean
isLibArchive
(Path path) Test if Path is any supported Java Library Archive type (suitable to use as a library in a classpath/classloader)static boolean
isMetaInfVersions
(Path path) Predicate to filter onMETA-INF/versions/*
tree in walk/stream results.static boolean
isModuleInfoClass
(Path path) Predicate to skipmodule-info.class
files.static boolean
isNotMetaInfVersions
(Path path) Predicate to skipMETA-INF/versions/*
tree from walk/stream results.static boolean
isNotModuleInfoClass
(Path path) Predicate to skipmodule-info.class
files.static boolean
Is the path a TLD Filestatic boolean
isWebArchive
(String filename) Is the filename a WAR file.static boolean
isWebArchive
(URI uri) Is the path a Web Archive File (not directory)static boolean
isWebArchive
(Path path) Is the path a Web Archive File (not directory)static boolean
Is the Path a file that ends in XML?static boolean
Is the Path a file that ends in XML?
-
Constructor Details
-
FileID
public FileID()
-
-
Method Details
-
getBasename
Retrieve the basename of a path. This is the name of the last segment of the path, with any dot suffix (e.g. ".war") removed- Parameters:
path
- The string path- Returns:
- The last segment of the path without any dot suffix
-
getFileName
Get the last segment of the URI returning it as the filename- Parameters:
uri
- the URI to look for the filename- Returns:
- The last segment of the uri
-
getFileName
Get the last segment of a String path returning it as the filename- Parameters:
path
- the string path to look for the filename- Returns:
- The last segment of the path
-
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
-
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.class
files.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.class
file
-
isNotModuleInfoClass
Predicate to skipmodule-info.class
files.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.class
file
-
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
-