added a useLines() methods on Reader to be able to use a line iterator (Iterator<String>) to process the file on a per line bases with the block in full control over how much of the file to process; though hit a couple of type inference issues
This commit is contained in:
+21
-6
@@ -10,18 +10,33 @@ import java.util.*
|
||||
class IoTest() : TestSupport() {
|
||||
val file = File("test/HelloWorld.txt")
|
||||
|
||||
fun testLineIteratorWithManualClose() {
|
||||
val reader = FileReader(file).buffered()
|
||||
try {
|
||||
val list = reader.lineIterator().toArrayList()
|
||||
assertEquals(arrayList("Hello", "World"), list)
|
||||
} finally {
|
||||
reader.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun testLineIterator() {
|
||||
val list = FileReader(file).buffered().lineIterator().toArrayList()
|
||||
/*
|
||||
// TODO compiler error
|
||||
// both these expressions causes java.lang.NoClassDefFoundError: collections/namespace
|
||||
val list = FileReader(file).useLines{it.toArrayList()}
|
||||
val list = FileReader(file).useLines<ArrayList<String>>{it.toArrayList()}
|
||||
|
||||
assertEquals(arrayList("Hello", "World"), list)
|
||||
*/
|
||||
}
|
||||
|
||||
fun testUse() {
|
||||
val list = ArrayList<String>()
|
||||
|
||||
val reader = FileReader(file).buffered()
|
||||
reader.close()
|
||||
|
||||
/**
|
||||
val list = ArrayList<String>()
|
||||
val reader = FileReader(file).buffered()
|
||||
|
||||
TODO compiler error?
|
||||
reader.use{
|
||||
val line = it.readLine()
|
||||
|
||||
Reference in New Issue
Block a user