FileInput.java

Go to the documentation of this file.
00001 
00010 package VisuBDD;
00011 
00012 import java.io.*; // Import the necessary classes for file input.
00013 import java.util.*; // Import utilities.
00014 
00015 public class FileInput {
00016   
00028   public static List readFile(java.util.List localList, java.util.List filenameList,
00029                               String filename) {
00030   
00031     List numberList = new Vector(); // list to store numbers
00032     String tmpString;               // temporary String holds a
00033                                     // single line from input file.
00034     int i = 1;
00035     double inputNumber = 0.0;       // Current input number read.
00036 
00037     try {   
00038       FileReader input = new FileReader(filename);
00039       BufferedReader inputReader = new BufferedReader(input);
00040       
00041       System.out.println("\nReading inputfile: " + filename);
00042       System.out.println("Content: ");
00043       
00044       tmpString = inputReader.readLine();       // temp String holds single
00045                                                 // line from input file
00046       boolean ignoreDescription;                   // Ignoring val descr.
00047 
00048       while (tmpString != null) {               // While not end of file...
00049         ignoreDescription = false;
00050 
00051         // If dividing list sign was found --> create new list.
00052         if (tmpString.equals("#")) {
00053           localList.add(numberList);
00054           if (i > 1) {
00055             filenameList.add(new String(filename + "(" + i + ")")); // add filename to list
00056           } else {
00057             filenameList.add(new String(filename));             // add filename to list
00058           } // if
00059           numberList = new Vector();
00060           i++;
00061         } else {
00062           try {
00063             // Parse String to double.
00064             inputNumber = Double.parseDouble(tmpString);
00065           } catch (NumberFormatException e3) {
00066 
00067             /* Temporary the value description output from the rabbit tool
00068                will be ignored.
00069 
00070                I need a visualizeation idea to display the descriptions and
00071                the belonging values.
00072                I cannot use colors, because of the potentially large number of
00073                descriptions.
00074 
00075                mvogel 2001-09-05
00076              */
00077 
00078             //System.out.println("Ignoring value description.");
00079 
00080            ignoreDescription = true;
00081           } // catch
00082 
00083           if (!ignoreDescription) {
00084             numberList.add(new Double(inputNumber));  // Append Elem to List.
00085             System.out.println(inputNumber + "; ");
00086           }
00087         } // if
00088         tmpString = inputReader.readLine();
00089       } // while
00090 
00091       // If last '#' was missing add numberList to localList;
00092       if (numberList.size() > 0) {
00093         localList.add(numberList);
00094           if (i > 1) {
00095             // add filename to list
00096             filenameList.add(new String(filename + "(" + i + ")"));
00097           } else {
00098             filenameList.add(new String(filename));  // add filename to list
00099           } // if
00100         } // if
00101 
00102     } // try
00103 
00104     catch (FileNotFoundException e1) {          // File not Found
00105       System.out.println("Runtime error in FileInput.readFile(List, List, "
00106                          + "String).");
00107       System.out.println(" The specified input file " + filename + " was"
00108                          + " not found.");
00109       System.exit(1);
00110     }
00111     catch (IOException e2) {                    // IO error
00112       System.out.println("Runtime error in FileInput.readFile(List, List, "
00113                          + "String).");
00114       System.out.println(" An I/O error occured while reading " + filename
00115                          + " .");
00116       System.exit(1);
00117     }
00118     
00119     return localList;                          // returns linked List
00120       
00121   } // readFile(String filename)
00122 
00123 } // class InputFile

Generated on Fri Jun 6 22:21:09 2008 for CrocoPat by  doxygen 1.5.1