// File: Client.java
// Time-stamp: "2005-01-22 09:21:03 calvanese"
// Purpose: Counter: solution part 3

import java.io.*;

public class Client {

  public static int[] readFromFile (String filename, Counter cnt)
                                                          throws IOException {
    // count the number of lines of the file
    BufferedReader brf = new BufferedReader(new FileReader(filename));
    int count = 0;
    String name = brf.readLine();
    while (name != null) {
      count++;
      name = brf.readLine();
    }
    brf.close();

    // add the requests and store the progressive numbers in the array
    brf = new BufferedReader(new FileReader(filename));
    int[] res = new int[count];
    int i = 0;
    name = brf.readLine();
    while (name != null) {
      res[i] = cnt.addRequest(name);
      i++;
      name = brf.readLine();
    }
    brf.close();

    return res;
  }
}
