You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "labkey-adam (via GitHub)" <gi...@apache.org> on 2023/09/30 16:58:00 UTC
[GitHub] [commons-io] labkey-adam opened a new pull request, #489: IO-811: Files.walk() direct and indirect callers fail to close the re…
labkey-adam opened a new pull request, #489:
URL: https://github.com/apache/commons-io/pull/489
…turned Stream<Path>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-io] garydgregory commented on a diff in pull request #489: IO-811: Files.walk() direct and indirect callers fail to close the re…
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #489:
URL: https://github.com/apache/commons-io/pull/489#discussion_r1341991452
##########
src/main/java/org/apache/commons/io/FileUtils.java:
##########
@@ -1996,7 +1996,28 @@ public static Iterator<File> iterateFiles(final File directory, final IOFileFilt
* @since 1.2
*/
public static Iterator<File> iterateFiles(final File directory, final String[] extensions, final boolean recursive) {
- return Uncheck.apply(d -> streamFiles(d, recursive, extensions).iterator(), directory);
+ return Uncheck.apply(d -> {
+ Stream<File> stream = streamFiles(d, recursive, extensions);
+ Iterator<File> iter = stream.iterator();
+
+ // Wrap the iterator to allow closing the stream after consumption
+ return new Iterator<File>(){
Review Comment:
Missing space.
##########
src/main/java/org/apache/commons/io/FileUtils.java:
##########
@@ -1996,7 +1996,28 @@ public static Iterator<File> iterateFiles(final File directory, final IOFileFilt
* @since 1.2
*/
public static Iterator<File> iterateFiles(final File directory, final String[] extensions, final boolean recursive) {
- return Uncheck.apply(d -> streamFiles(d, recursive, extensions).iterator(), directory);
+ return Uncheck.apply(d -> {
+ Stream<File> stream = streamFiles(d, recursive, extensions);
+ Iterator<File> iter = stream.iterator();
+
+ // Wrap the iterator to allow closing the stream after consumption
+ return new Iterator<File>(){
+ @Override
+ public boolean hasNext() {
+ boolean ret = iter.hasNext();
+
+ if (!ret)
Review Comment:
Always use blocks -> { }
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-io] labkey-adam commented on a diff in pull request #489: IO-811: Files.walk() direct and indirect callers fail to close the re…
Posted by "labkey-adam (via GitHub)" <gi...@apache.org>.
labkey-adam commented on code in PR #489:
URL: https://github.com/apache/commons-io/pull/489#discussion_r1341997726
##########
src/main/java/org/apache/commons/io/FileUtils.java:
##########
@@ -1996,7 +1996,28 @@ public static Iterator<File> iterateFiles(final File directory, final IOFileFilt
* @since 1.2
*/
public static Iterator<File> iterateFiles(final File directory, final String[] extensions, final boolean recursive) {
- return Uncheck.apply(d -> streamFiles(d, recursive, extensions).iterator(), directory);
+ return Uncheck.apply(d -> {
+ Stream<File> stream = streamFiles(d, recursive, extensions);
+ Iterator<File> iter = stream.iterator();
+
+ // Wrap the iterator to allow closing the stream after consumption
+ return new Iterator<File>(){
+ @Override
+ public boolean hasNext() {
+ boolean ret = iter.hasNext();
+
+ if (!ret)
Review Comment:
Done
##########
src/main/java/org/apache/commons/io/FileUtils.java:
##########
@@ -1996,7 +1996,28 @@ public static Iterator<File> iterateFiles(final File directory, final IOFileFilt
* @since 1.2
*/
public static Iterator<File> iterateFiles(final File directory, final String[] extensions, final boolean recursive) {
- return Uncheck.apply(d -> streamFiles(d, recursive, extensions).iterator(), directory);
+ return Uncheck.apply(d -> {
+ Stream<File> stream = streamFiles(d, recursive, extensions);
+ Iterator<File> iter = stream.iterator();
+
+ // Wrap the iterator to allow closing the stream after consumption
+ return new Iterator<File>(){
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-io] garydgregory closed pull request #489: IO-811: Files.walk() direct and indirect callers fail to close the re…
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory closed pull request #489: IO-811: Files.walk() direct and indirect callers fail to close the re…
URL: https://github.com/apache/commons-io/pull/489
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-io] garydgregory commented on a diff in pull request #489: IO-811: Files.walk() direct and indirect callers fail to close the re…
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #489:
URL: https://github.com/apache/commons-io/pull/489#discussion_r1342131817
##########
src/main/java/org/apache/commons/io/FileUtils.java:
##########
@@ -1996,7 +1996,29 @@ public static Iterator<File> iterateFiles(final File directory, final IOFileFilt
* @since 1.2
*/
public static Iterator<File> iterateFiles(final File directory, final String[] extensions, final boolean recursive) {
- return Uncheck.apply(d -> streamFiles(d, recursive, extensions).iterator(), directory);
+ return Uncheck.apply(d -> {
+ Stream<File> stream = streamFiles(d, recursive, extensions);
+ Iterator<File> iter = stream.iterator();
+
+ // Wrap the iterator to allow closing the stream after consumption
+ return new Iterator<File>() {
+ @Override
+ public boolean hasNext() {
+ boolean ret = iter.hasNext();
+
+ if (!ret) {
+ stream.close();
+ }
+
+ return ret;
+ }
+
+ @Override
+ public File next() {
+ return iter.next();
+ }
+ };
+ }, directory);
Review Comment:
No need for an anonymous class:
```
return StreamIterator.iterator(Uncheck.get(() -> streamFiles(directory, recursive, extensions)));
```
##########
src/main/java/org/apache/commons/io/FileUtils.java:
##########
@@ -2238,7 +2260,11 @@ public static Collection<File> listFiles(final File directory, final IOFileFilte
* @return a collection of java.io.File with the matching files
*/
public static Collection<File> listFiles(final File directory, final String[] extensions, final boolean recursive) {
- return Uncheck.apply(d -> toList(streamFiles(d, recursive, extensions)), directory);
+ return Uncheck.apply(d -> {
Review Comment:
I've adopted a variant of this fix in git master. You are credited in `changes.xml` :-)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-io] garydgregory commented on pull request #489: IO-811: Files.walk() direct and indirect callers fail to close the re…
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #489:
URL: https://github.com/apache/commons-io/pull/489#issuecomment-1742082626
Closing, see above. Jira ticket resolved.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org