Bug in DataInputStream (readInt)

Martin Kahlert martin.kahlert@infineon.com
Tue Sep 25 06:19:00 GMT 2001


Hi!
This was the old code (in gcc-3.0.1) for DataInputStream::readInt:
{
 int a = in.read();
 int b = in.read();
 int c = in.read();
 int d = in.read();
 if (d < 0)
 throw new EOFException();
 return (((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff));
}
In 3.1 it reads
public final int readInt() throws IOException
{
 int count = in.read (buf, 0, 4);
 if (count < 4)
 throw new EOFException();
 return convertToInt(buf);
}
which is wrong: My application runs into a situation, where it has 3 bytes in
the buffer (BufferedInputStream).
Thus count = 3. This is not an EOF, it would be only an EOF, if another call
to read for the remaining byte would return anything < 0.
So why has this been changed? Is there some deep rewrite of the IO classes
happening? I ask, because i want to know if BufferedInputStream::read should
try harder to obtain all wanted bytes, or if DataInputStream should re-call
BufferedInputStream::read again until it has all the bytes it wants to have.
Thanks for clarification,
Martin.
-- 
The early bird catches the worm. If you want something else for 
breakfast, get up later.


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /