summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Cunei <antonio.cunei@epfl.ch>2009-01-07 17:29:05 +0000
committerAntonio Cunei <antonio.cunei@epfl.ch>2009-01-07 17:29:05 +0000
commit166563559ba72f3e2e0309396261030c14effe4d (patch)
treee6eedf40933936cc769995ed6f254227f4437ab9
parentb0de8aa196b209f84269b715a1f880b0a393d4ec (diff)
downloadscala-166563559ba72f3e2e0309396261030c14effe4d.tar.gz
scala-166563559ba72f3e2e0309396261030c14effe4d.tar.bz2
scala-166563559ba72f3e2e0309396261030c14effe4d.zip
Fix for #1624.
The code logic of this fragment was wrong, and worked mainly because the CharsetDecoder usually generates the same number of characters in output as are given in input. Using special characters would change that, leading to a condition by which the resulting CharBuffer would never eventually empty.
-rw-r--r--src/library/scala/io/BufferedSource.scala17
1 files changed, 5 insertions, 12 deletions
diff --git a/src/library/scala/io/BufferedSource.scala b/src/library/scala/io/BufferedSource.scala
index cdcc56d190..b71b6fe0d4 100644
--- a/src/library/scala/io/BufferedSource.scala
+++ b/src/library/scala/io/BufferedSource.scala
@@ -65,18 +65,11 @@ abstract class BufferedSource(byteChannel: ReadableByteChannel, decoder: Charset
Thread.sleep(1); // wait 1 ms for new data
num_bytes = byteChannel.read(byteBuffer)
}
- num_bytes match {
- case -1 =>
- endOfInput = true;
- byteBuffer.position(0)
- decoder.decode(byteBuffer, charBuffer, true)
- decoder.flush(charBuffer)
- case num_bytes =>
- endOfInput = false
- byteBuffer.flip()
- decoder.decode(byteBuffer, charBuffer, false)
- charBuffer.flip()
- }
+ endOfInput = (num_bytes == -1)
+ byteBuffer.flip()
+ decoder.decode(byteBuffer, charBuffer, endOfInput)
+ if (endOfInput) decoder.flush(charBuffer)
+ charBuffer.flip()
}
override val iter = new Iterator[Char] {
var buf_char = {