Remove uses of File#listFiles #449

Closed
Isira-Seneviratne wants to merge 2 commits from Remove_listFiles into devel
Isira-Seneviratne commented 2023-08-07 01:36:17 +00:00 (Migrated from github.com)

The File class's listFiles method has a disadvantage in that it lists all of a directory's files at once, which can be problematic for directories with a lot of files.

This PR switches to using the DirectoryStream and file walking APIs introduced in Java 7, which allow files to be lazily loaded on Android 8.0 and later. On Android versions below 8.0, the old API is still used to retrieve the files.

The `File` class's `listFiles` method has a [disadvantage](https://www.baeldung.com/java-list-directory-files) in that it lists all of a directory's files at once, which can be problematic for directories with a lot of files. This PR switches to using the [`DirectoryStream`](https://docs.oracle.com/javase/7/docs/api/java/nio/file/DirectoryStream.html) and [file walking](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#walkFileTree-java.nio.file.Path-java.util.Set-int-java.nio.file.FileVisitor-) APIs introduced in Java 7, which allow files to be lazily loaded on Android 8.0 and later. On Android versions below 8.0, the old API is [still used](https://github.com/google/desugar_jdk_libs/blob/675406d1843b8a039a20861b5e30d2c6298dd338/jdk11/src/addon/java/desugar/sun/nio/fs/DesugarLinuxFileSystemProvider.java#L416) to retrieve the files.
Koitharu commented 2023-08-07 15:14:29 +00:00 (Migrated from github.com)

It looks good but we really do not want to enable desugaring. I'll look if it possible to use Okio for this

It looks good but we really do not want to enable desugaring. I'll look if it possible to use Okio for this
Koitharu (Migrated from github.com) reviewed 2023-08-07 15:18:26 +00:00
Koitharu commented 2023-08-09 09:24:26 +00:00 (Migrated from github.com)

Take a look, I did it in another way without desugaring

Take a look, I [did it](https://github.com/KotatsuApp/Kotatsu/commit/a5d99db10594f3cdb15c36a4a7e21966685eca92) in another way without desugaring

Pull request closed

Sign in to join this conversation.