// TextTester.java // Use AS-IS to test CS 10 assignment 5, part 1, Fall 2008 // cmc, updated 11/18/08 import java.io.IOException; public class TextTester { public static void main(String[] args) { if (args.length < 1 || args.length > 2) fatalMessage("usage: java TextTester [-u] source"); String source = null; char sourceType = 'f'; // file by default for (String arg : args) { if (arg.charAt(0) == '-') { // an option String option = arg.substring(1, 2); if (option.equals("u")) sourceType = 'u'; else fatalMessage("bad option: " + arg); } else { // input source if (source == null) source = arg; else fatalMessage("extra input source: " + arg); } } // verify a source was entered if (source == null) fatalMessage("did not enter source of text"); // try to get and print the text try { TextGetter getter; if (sourceType == 'f') getter = new FileText(source); else getter = new WebText(source); String text = getter.getText(); System.out.print(text); } catch(IOException exception) { System.err.println("Input/output error - " + exception); } } // utility prints error message and exits private static void fatalMessage(String message) { System.err.println(message); System.exit(1); } }