Add a readLine() method
authorjjenista <jjenista>
Mon, 23 Feb 2009 23:09:59 +0000 (23:09 +0000)
committerjjenista <jjenista>
Mon, 23 Feb 2009 23:09:59 +0000 (23:09 +0000)
Robust/src/ClassLibrary/FileInputStream.java

index dbc58d4cdca38c44f45cbe80dbef23c6c2ef8c86..5a833ade1948c8a3e5e19988059cebbfcb24da5a 100644 (file)
@@ -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);
   }