aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/io/InputStreamReader.java
diff options
context:
space:
mode:
authorMohan Embar <gnustuff@thisiscool.com>2004-01-30 06:33:43 +0000
committerMohan Embar <membar@gcc.gnu.org>2004-01-30 06:33:43 +0000
commitae30b3b25d4ec2a0cc1eff88ffcafd726f9cbe7a (patch)
treef57a095d33f60f3fd7a5ada51e038edd80f676f8 /libjava/java/io/InputStreamReader.java
parenteadccbea1257934ae7446a921cdb1c12431b8f58 (diff)
downloadgcc-ae30b3b25d4ec2a0cc1eff88ffcafd726f9cbe7a.zip
gcc-ae30b3b25d4ec2a0cc1eff88ffcafd726f9cbe7a.tar.gz
gcc-ae30b3b25d4ec2a0cc1eff88ffcafd726f9cbe7a.tar.bz2
BufferedReader.java (sbuf): New field.
* java/io/BufferedReader.java (sbuf): New field. (readLine): Use String.valueOf instead of new String() as per Per Bothner's suggestion. Use instance sbuf field instead of a local StringBuffer instance. * java/io/InputStreamReader.java (read(char[],int,int)): Pass the caller's buffer to refill(). (read(void)): Pass our internal work buffer to refill if our input queue is empty. (refill): Changed return type to int. Use the specified buffer instead of our work buffer as per Bryce McKinlay's suggestion. Return the number of characters read or -1 for EOF. From-SVN: r76927
Diffstat (limited to 'libjava/java/io/InputStreamReader.java')
-rw-r--r--libjava/java/io/InputStreamReader.java38
1 files changed, 16 insertions, 22 deletions
diff --git a/libjava/java/io/InputStreamReader.java b/libjava/java/io/InputStreamReader.java
index 05ed5fe..07be132 100644
--- a/libjava/java/io/InputStreamReader.java
+++ b/libjava/java/io/InputStreamReader.java
@@ -1,5 +1,5 @@
/* InputStreamReader.java -- Reader than transforms bytes to chars
- Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -231,10 +231,8 @@ public class InputStreamReader extends Reader
int wavail = wcount - wpos;
if (wavail <= 0)
{
- // Nothing waiting, so refill our buffer.
- if (! refill ())
- return -1;
- wavail = wcount - wpos;
+ // Nothing waiting, so refill their buffer.
+ return refill(buf, offset, length);
}
if (length > wavail)
@@ -262,24 +260,24 @@ public class InputStreamReader extends Reader
int wavail = wcount - wpos;
if (wavail <= 0)
{
- // Nothing waiting, so refill our buffer.
- if (! refill ())
+ // Nothing waiting, so refill our internal buffer.
+ wpos = wcount = 0;
+ if (work == null)
+ work = new char[100];
+ int count = refill(work, 0, work.length);
+ if (count == -1)
return -1;
+ wcount += count;
}
return work[wpos++];
}
}
- // Read more bytes and convert them into the WORK buffer.
- // Return false on EOF.
- private boolean refill () throws IOException
+ // Read more bytes and convert them into the specified buffer.
+ // Returns the number of converted characters or -1 on EOF.
+ private int refill(char[] buf, int offset, int length) throws IOException
{
- wcount = wpos = 0;
-
- if (work == null)
- work = new char[100];
-
for (;;)
{
// We have knowledge of the internals of BufferedInputStream
@@ -290,17 +288,13 @@ public class InputStreamReader extends Reader
boolean r = in.pos < in.count || in.refill ();
in.reset ();
if (! r)
- return false;
+ return -1;
converter.setInput(in.buf, in.pos, in.count);
- int count = converter.read (work, wpos, work.length - wpos);
+ int count = converter.read(buf, offset, length);
in.skip(converter.inpos - in.pos);
if (count > 0)
- {
- wcount += count;
- return true;
- }
+ return count;
}
}
-
} // class InputStreamReader