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:
James Strachan
2011-12-22 09:36:18 +00:00
parent a7810c4396
commit 2274ab48ab
2 changed files with 33 additions and 15 deletions
+21 -6
View File
@@ -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()