RFR: 8057113: (fs) Path should have a method to obtain the filename extension [v14]
Roger Riggs
rriggs at openjdk.org
Tue Jul 26 19:55:18 UTC 2022
On Tue, 26 Jul 2022 00:09:09 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 18 additional commits since the last revision:
>
> - 8057113: Revert return type back to a nullable-String; update test
> - Merge
> - 8057113: Remove extensions() test method; add threthree new test cases
> - 8057113: Revert excision of wild cards from imports
> - 8057113: Add class level apiNote; improve getExtension() specification; remove hasExtension() and replaceExtension()
> - Merge
> - 8057113: Change @since annotation to 20
> - Merge
> - 8057113: Remove superfluous new Object[] statements from test
> - 8057113: Fix getExtension() commcents; improve hasExtension() implementation
> - ... and 8 more: https://git.openjdk.org/jdk/compare/a08870fa...23ca3f10
Changes requested by rriggs (Reviewer).
src/java.base/share/classes/java/nio/file/Path.java line 102:
> 100: * Otherwise stated, the internal representation might not be recoverable
> 101: * from the derived path string. This applies to the {@code Path} as a whole
> 102: * as well as to its components.
This comment doesn't seem specific to the enhancement proposed.
And its a bit vague, if/when included it might benefit from an example or mentioning the character set encoding of file names, if that's the context.
src/java.base/share/classes/java/nio/file/Path.java line 305:
> 303: } else if (length == 2 &&
> 304: !(fileNameString.charAt(0) == '.' ||
> 305: fileNameString.charAt(1) != '.')) {
I would have coded it as:
(length == 2 &&
fileNameString.charAt(0) != '.' &&
fileNameString.charat(1) == '.')) {
As a better match for the comment.
test/jdk/java/nio/file/Path/Extensions.java line 64:
> 62: {".profile.sh", "sh"},
> 63: {"..foo", "foo"},
> 64: {".....foo", "foo"},
Duplicates the test of line 53.
test/jdk/java/nio/file/Path/Extensions.java line 77:
> 75: {"x.zip", "zip"},
> 76: {"y.gzip", "gzip"},
> 77: {"z.jar", "jar"},
Fewer test cases of a file with a 3 or 4 character extension would be fine too.
Algorithm-wise they are all the same but may give a warm fuzzy that a favorite extension is covered.
-------------
PR: https://git.openjdk.org/jdk/pull/8066
More information about the nio-dev
mailing list