adding a test case
[IRC.git] / Robust / src / Tests / TestreadFromFile.java
1 /**
2  * Tests read from a  file that uses buffering directly, thereby eliminating the read method calls
3  * to read number of rows from an input txt file
4  **/
5 public class TestreadFromFile {
6   public static void main(String[] args) {
7     int numRows = 0;
8     int MAX_LINE_LENGTH = 1000000; /* max input is 400000 one digit input + spaces */
9     String filename;
10     filename = "input/random-n2048-d16-c16.txt";
11     FileInputStream inputFile = new FileInputStream(filename);
12     byte buf[] = new byte[MAX_LINE_LENGTH];
13     int n;
14     while ((n = inputFile.read(buf)) != 0) {
15       for (int i = 0; i < n; i++) {
16         if (buf[i] == '\n')
17           numRows++;
18       }
19     }
20     inputFile.close();
21     System.out.println("numRows= " +numRows);
22   }
23 }
24
25 /**
26  * compile:
27  * ../buildscript TestreadFromFile.java -mainclass TestreadFromFile -o TestreadFromFile
28  **/