Gets the book info, creating it if necessary.
if (bookInfo == null) {
// First request - create the data
ArrayList list = new ArrayList();
try {
InputStream is =
BookServiceServantData.class.getResourceAsStream("booklist.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = reader.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line, "!");
if (st.countTokens() == 4) {
list.add(new BookInfo(st.nextToken(), st.nextToken(),
st.nextToken(), Double.parseDouble(st.nextToken())));
}
}
} catch (Exception ex) {
// Just return an empty or partial list
ex.printStackTrace();
}
// Convert the list to an array
bookInfo = new BookInfo[list.size()];
list.toArray(bookInfo);
}
return bookInfo;