Fixed directory stream leak
This commit is contained in:
@@ -22,7 +22,6 @@ import java.io.InputStreamReader
|
|||||||
import java.net.URI
|
import java.net.URI
|
||||||
import java.nio.file.*
|
import java.nio.file.*
|
||||||
import java.nio.file.attribute.BasicFileAttributes
|
import java.nio.file.attribute.BasicFileAttributes
|
||||||
import java.nio.file.StandardOpenOption
|
|
||||||
|
|
||||||
data class File constructor(internal val javaPath: Path) {
|
data class File constructor(internal val javaPath: Path) {
|
||||||
constructor(parent: Path, child: String): this(parent.resolve(child))
|
constructor(parent: Path, child: String): this(parent.resolve(child))
|
||||||
@@ -50,14 +49,7 @@ data class File constructor(internal val javaPath: Path) {
|
|||||||
val isAbsolute
|
val isAbsolute
|
||||||
get() = javaPath.isAbsolute()
|
get() = javaPath.isAbsolute()
|
||||||
val listFiles: List<File>
|
val listFiles: List<File>
|
||||||
get() {
|
get() = Files.newDirectoryStream(javaPath).use { stream -> stream.map { File(it) } }
|
||||||
val stream = Files.newDirectoryStream(javaPath)
|
|
||||||
val result = mutableListOf<File>()
|
|
||||||
for (entry in stream) {
|
|
||||||
result.add(File(entry))
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
fun child(name: String) = File(this, name)
|
fun child(name: String) = File(this, name)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user