RFR: 8298318: (fs) APIs for handling filename extensions
Roger Riggs
rriggs at openjdk.org
Tue Oct 24 18:12:31 UTC 2023
On Tue, 24 Oct 2023 17:29:41 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> How would this work for the case of "compound extensions" such as `tar.gz` where one might want to end up with just `tar` or with `zip`, depending?
I'd view that a sequence of extensions so it would take a double application of withExtension to replace both. I.e.
Path path = Path.of("photos.tar.gz");
Path newP = path.withExtension("") // remove .gz; if there was no extension it would return the base
.withExtension(".zip"); -> "photos.zip"
// Testing for a compound extension
if (path.getExtension().equals("gz") && path.withExtension("").getExtension().equals("tar")) {...}
// Switching from zip to tar.gz is easier; It removes one extension and adds the string.
path.withExtension("tar.gz");
// Alternatively revert to old ways; no real help in this case.
path.filename().endsWith(".tar.gz");
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16226#issuecomment-1777765764
More information about the nio-dev
mailing list