scala.io.BufferedSourceクラスのバグの修正
ちょっと直してみた。(まだバグがあるかもしれないけど)
liftwebの日本語処理がおかしいときはお試しあれ。(自己責任でお願いします。。。)
Index: BufferedSource.scala =================================================================== --- BufferedSource.scala (revision 15559) +++ BufferedSource.scala (working copy) @@ -60,6 +60,7 @@ def fillBuffer() = { byteBuffer.compact() charBuffer.position(0) + charBuffer.limit(charBuffer.capacity); var num_bytes = byteChannel.read(byteBuffer) while (0 == num_bytes) { Thread.sleep(1); // wait 1 ms for new data @@ -65,10 +66,10 @@ Thread.sleep(1); // wait 1 ms for new data num_bytes = byteChannel.read(byteBuffer) } + byteBuffer.flip() num_bytes match { case -1 => endOfInput = true; - byteBuffer.position(0) decoder.decode(byteBuffer, charBuffer, true) decoder.flush(charBuffer) case num_bytes => @@ -73,10 +74,9 @@ decoder.flush(charBuffer) case num_bytes => endOfInput = false - byteBuffer.flip() decoder.decode(byteBuffer, charBuffer, false) - charBuffer.flip() } + charBuffer.flip(); } override val iter = new Iterator[Char] { var buf_char = { @@ -86,12 +86,12 @@ def hasNext = { charBuffer.remaining() > 0 || !endOfInput} def next = { val c = buf_char - if (charBuffer.remaining() == 0) { + if (charBuffer.remaining() == 0 && !endOfInput) { fillBuffer() } - if (!endOfInput) { - buf_char = charBuffer.get() - } + if (charBuffer.remaining() >= 1) { + buf_char = charBuffer.get() + } c } }