If a Buf is made by File.mmap, its methods which should return null if the end of stream has been reached (e.g. readChar, readLine), spawn java.nio.BufferUnderflowException instead on this condition. Looks like a bug.
Buf b := File.make(`filepath`).mmap
Str? s := null
try {
Int i := 0
while (null != (s = b.readLine)) {
echo("$i: $s")
++i
}
} finally {
b.close
}
It prints the entire file and then crashes with the above exception. However, if File.open is used, it works fine.
brianWed 16 Mar 2011
Promoted to ticket #1448 and assigned to brian
Yeah it doesn't look like nio ByteBuffer has a method that we really need - to read the bytes available and return actual number read (which is how every other Java input stream works). I will have to dig into it to see the best way to handle that case without introducing any big performance penalty.
If anyone else knows NIO well and wants to help with this bug, please shoot me an email.
brianThu 2 Jun 2011
Ticket resolved in 1.0.59
Fixed mmap implementation to use java.nio.Buffer.remaining to avoid under flow exceptions.
dsav Wed 16 Mar 2011
If a Buf is made by File.mmap, its methods which should return null if the end of stream has been reached (e.g. readChar, readLine), spawn java.nio.BufferUnderflowException instead on this condition. Looks like a bug.
Code example is below:
It prints the entire file and then crashes with the above exception. However, if File.open is used, it works fine.
brian Wed 16 Mar 2011
Promoted to ticket #1448 and assigned to brian
Yeah it doesn't look like nio ByteBuffer has a method that we really need - to read the bytes available and return actual number read (which is how every other Java input stream works). I will have to dig into it to see the best way to handle that case without introducing any big performance penalty.
If anyone else knows NIO well and wants to help with this bug, please shoot me an email.
brian Thu 2 Jun 2011
Ticket resolved in 1.0.59
Fixed mmap implementation to use
java.nio.Buffer.remaining
to avoid under flow exceptions.