java.io.DataInputStream.readLine() fixes

Robert Zawiasa bozo at bibl.u-szeged.hu
Fri Oct 2 06:10:44 PDT 1998


JDK 1.1 API docs say:

1) java.io.DataInputStream.readLine() is @deprecated
2) it returns the next line of text from the input stream, or null if no
   bytes are read before end-of-file is reached,
   (my interpretation: empty line terminated with CR/LF => "", instead of null)
3) line-terminating character(s), if any, are not returned as part of 
   the string that is returned

here's the "diff -u DataInputStream.java" against the current version below..
let me ask somebody to commit my changes, I'm still a cvs newbie
having no write access to the central repository yet. thanx.

up for adventures!

Robert

Index: DataInputStream.java
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/javalib/java/io/DataInputStream.java,v
retrieving revision 1.1
diff -u -r1.1 DataInputStream.java
--- DataInputStream.java	1998/07/14 17:02:01	1.1
+++ DataInputStream.java	1998/10/02 12:56:02
@@ -79,12 +79,17 @@
 	return temp;
 }
 
+/**
+ * @deprecated
+ */
 final public String readLine() throws IOException
 {
 	StringBuffer buffer = new StringBuffer();
 
+	int data;
+
 	for (;;) {
-		int data = super.read();
+		data = super.read();
 
 		if (data == -1) {
 			break;
@@ -104,22 +109,18 @@
 			}
 
 			cdata = (char)data;
-			if (cdata == '\n') {
-				buffer.append(cdata);
-			}
-			else {
+			if (cdata != '\n') {
 				/* Jump back to mark */
 				reset();
 			}
 			break;
 		}
-		else {
-			buffer.append(cdata);
-		}
+
+		buffer.append(cdata);
 	}
 
 	if (buffer.length() == 0) {
-		return (null);
+		return ((data == -1) ? null : "");
 	}
 	else {
 		return (buffer.toString());


More information about the kaffe mailing list