1 |
/* PushbackInputStream.java -- An input stream that can unread bytes |
/* PushbackInputStream.java -- An input stream that can unread bytes |
2 |
Copyright (C) 1998, 1999, 2001, 2001 Free Software Foundation, Inc. |
Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
116 |
*/ |
*/ |
117 |
public int available() throws IOException |
public int available() throws IOException |
118 |
{ |
{ |
119 |
return pos + super.available(); |
return (buf.length - pos) + super.available(); |
120 |
} |
} |
121 |
|
|
122 |
/** |
/** |
200 |
*/ |
*/ |
201 |
public synchronized int read(byte[] b, int off, int len) throws IOException |
public synchronized int read(byte[] b, int off, int len) throws IOException |
202 |
{ |
{ |
|
if (off < 0 || len < 0 || off + len > b.length) |
|
|
throw new ArrayIndexOutOfBoundsException(); |
|
|
|
|
203 |
int numBytes = Math.min(buf.length - pos, len); |
int numBytes = Math.min(buf.length - pos, len); |
204 |
if (numBytes > 0) |
if (numBytes > 0) |
205 |
{ |
{ |
206 |
System.arraycopy (buf, pos, b, off, numBytes); |
System.arraycopy (buf, pos, b, off, numBytes); |
207 |
pos += numBytes; |
pos += numBytes; |
208 |
return numBytes; |
len -= numBytes; |
209 |
|
off += numBytes; |
210 |
} |
} |
211 |
|
|
212 |
return super.read(b, off, len); |
if (len > 0) |
213 |
|
{ |
214 |
|
len = super.read(b, off, len); |
215 |
|
if (len == -1) // EOF |
216 |
|
return numBytes > 0 ? numBytes : -1; |
217 |
|
numBytes += len; |
218 |
|
} |
219 |
|
return numBytes; |
220 |
} |
} |
221 |
|
|
222 |
/** |
/** |