RFR: 8057113: (fs) Path should have a method to obtain the filename extension [v2]

Roger Riggs rriggs at openjdk.java.net
Thu Apr 7 16:06:49 UTC 2022


On Fri, 1 Apr 2022 20:15:17 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Resurrection of the proposal to add a method to obtain the filename extension originated in PR [2319](https://github.com/openjdk/jdk/pull/2319).
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8057113: Fix variable name in @return verbiage

I would include:

2. `default String getExtension(String default)` returns the extension of the string representation of the path

4. `default boolean hasExtension(String extension, boolean ignoreCase)` returns whether the string representation of the path has the specified extension, optionally ignoring case

   An alternative to case insensitive is  `Optional<String> hasExtension(String ext, String... extensions);`
   It allows at least one extension and a list of possible other extensions and returns the first one found.
   
5ish. `Path replaceExtension(String extension)` replaces the path's extension with the specified extension
   No particular bias against `removeExtension` but if total method count is an issue
   `replaceExtension` can be used to remove an extension with an empty string argument

These can avoid needing to convert Paths fully to strings and back; retaining the implementation
specific representation and giving the developer a familiar string based API.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8066


More information about the nio-dev mailing list