package java.io;


/*
 * Java core library component.
 *
 * Copyright (c) 1997, 1998
 *      Transvirtual Technologies, Inc.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file.
 */
public class PushbackInputStream
  extends FilterInputStream
{
	protected byte[] buf;
	protected int pos;

public PushbackInputStream(InputStream in) {
	this(in, 1);
}

public PushbackInputStream(InputStream in, int size) {
	super(in);
	buf = new byte[size];
	pos = buf.length;
}

public int available() throws IOException
{
	return (super.available() + (buf.length - pos));
}

public boolean markSupported() {
	return (false);
}

public int read() throws IOException {
	int b;
	if (pos < buf.length) {
		b = (int)buf[pos++];
	}
	else {
		b = super.read();
	}
	return (b & 0xFF);
}

public int read(byte cbuf[], int off, int len) throws IOException {
	int cnt = 0;
	while (pos < buf.length && len > 0) {
		cbuf[off++] = buf[pos++];
		len--;
		cnt++;
	}
	if (len > 0) {
		int r = super.read(cbuf, off, len);
		if (r == -1) {
			if (cnt == 0) {
				cnt = -1;
			}
		}
		else {
			cnt += r;
		}
	}
	return (cnt);
}

public void unread(byte cbuf[]) throws IOException {
	unread(cbuf, 0, cbuf.length);
}

public void unread(byte cbuf[], int off, int len) throws IOException {
	if (pos < len) {
		throw new IOException("pushback buffer is full");
	}
	pos -= len;
	System.arraycopy(cbuf, off, buf, pos, len);
}

public void unread(int c) throws IOException {
	if (pos == 0) {
		throw new IOException("pushback buffer is full");
	}
	pos--;
	buf[pos] = (byte)c;
}
}

@@ -715,18 +715,14 @@
  %7B%0A%09
-int b;%0A%09if
+return
  (po
@@ -741,84 +741,43 @@
 th) 
-%7B%0A%09%09b = (int)buf%5Bpos++%5D;%0A%09%7D%0A%09else %7B%0A%09%09b = super.read();%0A%09%7D%0A%09return (b & 0xFF
+? (buf%5Bpos++%5D & 0xff) : super.read(
 );%0A%7D

Fix bug in read() method: it was impossible for it to ever return -1