Bug fix in detecting EOF for input streams in readLine
authorjjenista <jjenista>
Fri, 27 Feb 2009 19:56:19 +0000 (19:56 +0000)
committerjjenista <jjenista>
Fri, 27 Feb 2009 19:56:19 +0000 (19:56 +0000)
Robust/src/ClassLibrary/FileInputStream.java
Robust/src/Tests/FileInputStreamTest/FileInputStreamTest.java [new file with mode: 0644]
Robust/src/Tests/FileInputStreamTest/makefile [new file with mode: 0644]
Robust/src/Tests/FileInputStreamTest/test.txt [new file with mode: 0644]

index 5a833ade1948c8a3e5e19988059cebbfcb24da5a..da717979f9b7ca445f275f72289c3ed0940bef09 100644 (file)
@@ -33,14 +33,15 @@ public class FileInputStream extends InputStream {
     int c = read();
     
     // if we're already at the end of the file
-    // don't even return the empty string
-    if( c == -1 ) { 
+    // or there is an error, don't even return
+    // the empty string
+    if( c <= 0 ) { 
       return null;
     }
 
-    while( c != '\n' && c != -1 ) {
+    while( c != '\n' && c > 0 ) {
       line += (char)c;
-      c = read();      
+      c = read();
     } 
 
     return line;
diff --git a/Robust/src/Tests/FileInputStreamTest/FileInputStreamTest.java b/Robust/src/Tests/FileInputStreamTest/FileInputStreamTest.java
new file mode 100644 (file)
index 0000000..7a32b57
--- /dev/null
@@ -0,0 +1,14 @@
+public class FileInputStreamTest {
+  static public void main( String[] args ) {
+    FileInputStream in = new FileInputStream( "test.txt" );
+
+    System.out.println( "#####################" );
+    String line = in.readLine();
+    while( line != null ) {
+      System.out.println( line );
+      line = in.readLine();
+    } 
+    System.out.println( "#####################" );
+    in.close();
+  }
+}
\ No newline at end of file
diff --git a/Robust/src/Tests/FileInputStreamTest/makefile b/Robust/src/Tests/FileInputStreamTest/makefile
new file mode 100644 (file)
index 0000000..a59670a
--- /dev/null
@@ -0,0 +1,9 @@
+all:
+       ../../buildscript -mainclass FileInputStreamTest *.java
+       a.bin
+
+clean:
+       rm -rf tmpbuilddirectory
+       rm -f a.bin
+       rm -f *~
+
diff --git a/Robust/src/Tests/FileInputStreamTest/test.txt b/Robust/src/Tests/FileInputStreamTest/test.txt
new file mode 100644 (file)
index 0000000..060f124
--- /dev/null
@@ -0,0 +1,8 @@
+gah
+
+ya
+
+yo
+
+pho
+dude