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
This commit is contained in:
Mohan Embar 2004-01-30 06:33:43 +00:00 committed by Mohan Embar
parent eadccbea12
commit ae30b3b25d
3 changed files with 41 additions and 25 deletions

View file

@ -1,5 +1,5 @@
/* BufferedReader.java
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -88,6 +88,11 @@ public class BufferedReader extends Reader
// This is package-private because it is used by LineNumberReader.
static final int DEFAULT_BUFFER_SIZE = 8192;
/**
* The line buffer for <code>readLine</code>.
*/
private StringBuffer sbuf = null;
/**
* Create a new <code>BufferedReader</code> that will read from the
* specified subordinate stream with a default buffer size of 8192 chars.
@ -439,7 +444,7 @@ public class BufferedReader extends Reader
int i = lineEnd(limit);
if (i < limit)
{
String str = new String(buffer, pos, i - pos);
String str = String.valueOf(buffer, pos, i - pos);
pos = i + 1;
// If the last char in the buffer is a '\r', we must remember
// to check if the next char to be read after the buffer is refilled
@ -450,7 +455,10 @@ public class BufferedReader extends Reader
pos++;
return str;
}
StringBuffer sbuf = new StringBuffer(200);
if (sbuf == null)
sbuf = new StringBuffer(200);
else
sbuf.setLength(0);
sbuf.append(buffer, pos, i - pos);
pos = i;
// We only want to return null when no characters were read before