Simplified the available() fix.

This commit is contained in:
jfrijters 2007-06-15 08:40:01 +00:00
Родитель 43d331ea6c
Коммит 9673d4db41
1 изменённых файлов: 13 добавлений и 37 удалений

Просмотреть файл

@ -28,7 +28,7 @@ public final class InputStreamWrapper extends java.io.InputStream
{ {
private cli.System.IO.Stream stream; private cli.System.IO.Stream stream;
private long markPosition = -1; private long markPosition = -1;
private int lookAhead = -1; private boolean atEOF;
public InputStreamWrapper(cli.System.IO.Stream stream) 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 public int read() throws java.io.IOException
{ {
if (lookAhead != -1)
{
int b = lookAhead;
lookAhead = -1;
return b;
}
try try
{ {
if (false) throw new cli.System.IO.IOException(); if (false) throw new cli.System.IO.IOException();
if (false) throw new cli.System.ObjectDisposedException(null); 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) 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.IO.IOException();
if (false) throw new cli.System.ObjectDisposedException(null); 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; atEOF = true;
lookAhead = -1; return -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;
} }
return count;
} }
catch (cli.System.IO.IOException x) 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. // return value as a cue to continue reading.
// As suggested by Mark Reinhold, we emulate InflaterInputStream's behavior // As suggested by Mark Reinhold, we emulate InflaterInputStream's behavior
// and return 0 after we've reached EOF and otherwise 1. // and return 0 after we've reached EOF and otherwise 1.
if (lookAhead == -1) return atEOF ? 0 : 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;
} }
} }