From: jjenista Date: Mon, 23 Feb 2009 23:09:59 +0000 (+0000) Subject: Add a readLine() method X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fc248cefa65209b11f924d7f2c6c40311ccd93c7;p=IRC.git Add a readLine() method --- diff --git a/Robust/src/ClassLibrary/FileInputStream.java b/Robust/src/ClassLibrary/FileInputStream.java index dbc58d4c..5a833ade 100644 --- a/Robust/src/ClassLibrary/FileInputStream.java +++ b/Robust/src/ClassLibrary/FileInputStream.java @@ -28,6 +28,24 @@ public class FileInputStream extends InputStream { return nativeRead(fd, b, b.length); } + public String readLine() { + String line = ""; + int c = read(); + + // if we're already at the end of the file + // don't even return the empty string + if( c == -1 ) { + return null; + } + + while( c != '\n' && c != -1 ) { + line += (char)c; + c = read(); + } + + return line; + } + public void close() { nativeClose(fd); }