diff --git a/classpath/ikvm/io/InputStreamWrapper.java b/classpath/ikvm/io/InputStreamWrapper.java index b48f8d99..e55ff302 100644 --- a/classpath/ikvm/io/InputStreamWrapper.java +++ b/classpath/ikvm/io/InputStreamWrapper.java @@ -28,7 +28,7 @@ public final class InputStreamWrapper extends java.io.InputStream { private cli.System.IO.Stream stream; private long markPosition = -1; - private int lookAhead = -1; + private boolean atEOF; public InputStreamWrapper(cli.System.IO.Stream stream) { @@ -37,17 +37,16 @@ public final class InputStreamWrapper extends java.io.InputStream public int read() throws java.io.IOException { - if (lookAhead != -1) - { - int b = lookAhead; - lookAhead = -1; - return b; - } try { if (false) throw new cli.System.IO.IOException(); if (false) throw new cli.System.ObjectDisposedException(null); - return stream.ReadByte(); + int i = stream.ReadByte(); + if (i == -1) + { + atEOF = true; + } + return i; } catch (cli.System.IO.IOException x) { @@ -86,21 +85,13 @@ public final class InputStreamWrapper extends java.io.InputStream { if (false) throw new cli.System.IO.IOException(); if (false) throw new cli.System.ObjectDisposedException(null); - if (lookAhead != -1) + int count = stream.Read(b, off, len); + if (count == 0) { - b[off] = (byte)lookAhead; - lookAhead = -1; - if (len > 1) - { - return stream.Read(b, off + 1, len - 1) + 1; - } - return 1; - } - else - { - int count = stream.Read(b, off, len); - return count == 0 ? -1 : count; + atEOF = true; + return -1; } + return count; } catch (cli.System.IO.IOException x) { @@ -183,22 +174,7 @@ public final class InputStreamWrapper extends java.io.InputStream // return value as a cue to continue reading. // As suggested by Mark Reinhold, we emulate InflaterInputStream's behavior // and return 0 after we've reached EOF and otherwise 1. - if (lookAhead == -1) - { - try - { - if (false) throw new cli.System.IO.IOException(); - if (false) throw new cli.System.ObjectDisposedException(null); - lookAhead = stream.ReadByte(); - } - catch (cli.System.IO.IOException x) - { - } - catch (cli.System.ObjectDisposedException x) - { - } - } - return lookAhead == -1 ? 0 : 1; + return atEOF ? 0 : 1; } }