RFR: 8057113: (fs) Path should have a method to obtain the filename extension [v18]
Alan Bateman
alanb at openjdk.org
Wed Aug 3 15:42:51 UTC 2022
On Mon, 1 Aug 2022 21:54:22 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: Remove API note
Thank you for persisting with this one, the original Path::getExtension method was prototyped more 12 years ago, the main issue at the being being trying to get to a saner definition of an extension. You've got this to a good place.
src/java.base/share/classes/java/nio/file/Path.java line 256:
> 254: * extension is the portion of the {@linkplain #getFileName file name}
> 255: * string after the last period character ('.', U+002E FULL STOP). Leading
> 256: * period characters in the string are ignored. If there is no extension,
Minor nit, you've got a double space in "no extension"
src/java.base/share/classes/java/nio/file/Path.java line 258:
> 256: * period characters in the string are ignored. If there is no extension,
> 257: * then {@code null} is returned. This will occur if the path has zero
> 258: * elements ({@link #getFileName()} returns {@code null}), the file name
The path has zero elements is correct but it might be clearer to say "The path doesn't have a file contain".
src/java.base/share/classes/java/nio/file/Path.java line 272:
> 270: * return lastPeriod == fileName.length() - 1 ?
> 271: * "" :
> 272: * fileName.substring(lastPeriod + 1);
Can L270-272 in the implSpec be cleaned up? It's okay to use the ternary operator but would be easier to read if there is parenthesis around the condition and the ? and : weren't at the end of the lines.
src/java.base/share/classes/java/nio/file/Path.java line 297:
> 295: if (lastPeriodIndex == length - 1) {
> 296: // null if all period characters, otherwise empty
> 297: return fileNameString.matches("\\.{" + length + "}") ?
Using a regular expression here is probably okay or the initial PR but I could imagine this show up in profiles and needing to be re-implemented.
-------------
PR: https://git.openjdk.org/jdk/pull/8066
More information about the nio-dev
mailing list