/[classpath]/classpath/java/io/PushbackInputStream.java
ViewVC logotype

Diff of /classpath/java/io/PushbackInputStream.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by mark, Tue Jan 22 22:26:59 2002 UTC revision 1.10 by bryce, Mon Mar 25 02:31:22 2002 UTC
# Line 1  Line 1 
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    
# Line 116  public class PushbackInputStream extends Line 116  public class PushbackInputStream extends
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    /**    /**
# Line 200  public class PushbackInputStream extends Line 200  public class PushbackInputStream extends
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    /**    /**

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26