// Always call super.init(config) first
super.init(config);
// Try to load the initial page counts from the saved persistent state
try {
FileReader fileReader = new FileReader(getClass().getName() + ".counts");
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line = null;
String uri = null;
String count = null;
int[] holder = null; // holder for the count, to make it an object
while ((line = bufferedReader.readLine()) != null) {
StringTokenizer tokenizer = new StringTokenizer(line);
if (tokenizer.countTokens() < 2) continue; // bogus line
uri = tokenizer.nextToken();
count = tokenizer.nextToken();
// Store the uri/count pair in the counts hashtable
// The count is saved as an int[1] to make it an "object"
try {
holder = new int[1];
holder[0] = Integer.parseInt(count);
counts.put(uri, holder);
}
catch (NumberFormatException e) { } // bogus line
}
}
catch (FileNotFoundException e) { } // no saved state
catch (IOException e) { } // problem during read