Fix file descriptor unlimited growth.

This commit is contained in:
Alexander Gorshenev
2019-03-15 22:56:39 +03:00
committed by Zalim Bashorov
parent 5fc0d85b3c
commit 51e862e793
@@ -31,7 +31,9 @@ fun File.map(mode: FileChannel.MapMode = FileChannel.MapMode.READ_ONLY,
if (mode == FileChannel.MapMode.READ_ONLY) "r" else "rw")
val fileSize = if (mode == FileChannel.MapMode.READ_ONLY)
file.length() else size.also { assert(size != -1L) }
return file.channel.map(mode, start, fileSize) // Shall we .also { file.close() }?
val channel = file.channel
return channel.map(mode, start, fileSize)
.also { channel.close() } // Channel close closes the file also.
}
class CombinedIrFileReader(file: File) {