Example #1
0
 /**
  * This is the analogue of {@code loadFromFilename}, and is intended to be included in a routine
  * that unpacks a text-serialized form of an object that incorporates an Index. NOTE: presumes
  * that the next readLine() will read in the first line of the portion of the text file
  * representing the saved Index. Currently reads until it encounters a blank line, consuming that
  * line and returning the Index. TODO: figure out how best to terminate: currently a blank line is
  * considered to be a terminator.
  *
  * @param br The Reader to read the index from
  * @return An Index read from a file
  */
 public static Index<String> loadFromReader(BufferedReader br) throws IOException {
   HashIndex<String> index = new HashIndex<String>();
   String line = br.readLine();
   // terminate if EOF reached, or if a blank line is encountered.
   while ((line != null) && (line.length() > 0)) {
     int start = line.indexOf('=');
     if (start == -1 || start == line.length() - 1) {
       continue;
     }
     index.add(line.substring(start + 1));
     line = br.readLine();
   }
   return index;
 }