Changes
[IRC.git] / Robust / src / Tests / mlp / stephen / Parser.java
1
2 public class Parser 
3 {
4         private File file;
5         private int[][] preBoard;
6         
7         public Parser(String filename)
8         {
9                 file = new File(filename);
10                 preBoard = new int[9][9];
11         }
12         
13         public int[][] go() 
14         {
15                 FileInputStream in = new FileInputStream(file.getPath());
16                 
17
18                 for(int row = 0; row < 9; row++)
19                 {
20                         //grabs the row we're on
21                         String temp = in.readLine();
22                         if(temp == null)
23                         {
24                                 System.out.println("Malformed file (not enough lines)");
25                                 return null;
26                         }
27
28                         //builds new scanner for the line
29                         StringTokenizer scan = new StringTokenizer(temp);
30                         if(scan.countTokens() < 8)
31                         {
32                                 System.out.println("Malformed file (not enough columns");
33                                 return null;
34                         }
35                         
36                         for(int column = 0; column < 9; column++)
37                         {
38                                 int num = Integer.parseInt(scan.nextToken());
39                                 
40                                 
41                                 //we may remove this later so that we can have everything instead of just this....
42                                 if(num > 9 || num < 0)
43                                 {
44                                         System.out.println("File is malformed");
45                                         return null;
46 //                                                      throw new FatalError("File is malformed");
47                                 }
48                                 else
49                                 {
50                                         preBoard[row][column] = num;
51                                 }
52                                 
53                         }
54                 }
55                 
56                 System.out.println("Parsing complete.");
57                 return preBoard;
58         }
59 }