[an error occurred while processing this directive]

FormattingTester.java


package ioutil;

import ioutil.Formatting;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 *  This class provides a main() method for testing the Formatting class.
 */
public class FormattingTester
extends Tester {

    /** FormattingTester() returns a new Tester.
     */
    public FormattingTester()
    throws FileNotFoundException, IOException {
	super();
    }  // public FormattingTester()

    /** addCommands() adds testing commands to the command table.
     */
    public void addCommands() {
	super.addCommands();

	commandTable.add(new Command() {
	    {
		name = new String("fsc");
		arguments = new String("w fc");
		brief = new String("displays a string of repeated characters");
		full = new String("displays a string with w copies of fc");
	    }
	    public void execute(LineScanner ls) {
		int w = ls.readInt();
		char fc = ls.readChar();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.fillString(w, fc) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("fsb");
		arguments = new String("w");
		brief = new String("displays a string of blanks");
		full = new String("displays a string with w blanks");
	    }
	    public void execute(LineScanner ls) {
		int w = ls.readInt();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.fillString(w) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("flc");
		arguments = new String("str w fc");
		brief = new String("displays a string filled left with " +
			"characters");
		full = new String("displays str in a field of width w " +
			"filled left with copies of fc");
	    }
	    public void execute(LineScanner ls) {
		String str = ls.readString();
		int w = ls.readInt();
		char fc = ls.readChar();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.filledLeft(str, w, fc) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("flb");
		arguments = new String("str w");
		brief = new String("displays a string filled left with " +
			"blanks");
		full = new String("displays str in a field of width w " +
			"filled left with blanks");
	    }
	    public void execute(LineScanner ls) {
		String str = ls.readString();
		int w = ls.readInt();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.filledLeft(str, w) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("frc");
		arguments = new String("str w fc");
		brief = new String("displays a string filled right with " +
			"characters");
		full = new String("displays str in a field of width w " +
			"filled right with copies of fc");
	    }
	    public void execute(LineScanner ls) {
		String str = ls.readString();
		int w = ls.readInt();
		char fc = ls.readChar();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.filledRight(str, w, fc) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("frb");
		arguments = new String("str w");
		brief = new String("displays a string filled right with " +
			"blanks");
		full = new String("displays str in a field of width w " +
			"filled right with blanks");
	    }
	    public void execute(LineScanner ls) {
		String str = ls.readString();
		int w = ls.readInt();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.filledRight(str, w) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("tl");
		arguments = new String("str w");
		brief = new String("displays a string trimmed on the left");
		full = new String("displays str trimmed on the left to " +
			"fit a field of width w");
	    }
	    public void execute(LineScanner ls) {
		String str = ls.readString();
		int w = ls.readInt();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.trimLeft(str, w) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("tr");
		arguments = new String("str w");
		brief = new String("displays a string trimmed on the right");
		full = new String("displays str trimmed on the right to " +
			"fit a field of width w");
	    }
	    public void execute(LineScanner ls) {
		String str = ls.readString();
		int w = ls.readInt();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.trimRight(str, w) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("dc");
		arguments = new String("n w fc");
		brief = new String("displays a decimal value");
		full = new String("displays the decimal value of n in a " +
			"field\n\tof width w with fill character fc");
	    }
	    public void execute(LineScanner ls) {
		int n = ls.readInt();
		int w = ls.readInt();
		char fc = ls.readChar();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.decimal(n, w, fc) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("db");
		arguments = new String("n w");
		brief = new String("displays a decimal value");
		full = new String("displays the decimal value of n in a " +
			"field\n\tof width w with blank fill characters");
	    }
	    public void execute(LineScanner ls) {
		int n = ls.readInt();
		int w = ls.readInt();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.decimal(n, w) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("hc");
		arguments = new String("n w fc");
		brief = new String("displays a hexadecimal value");
		full = new String("displays the hexadecimal value of n in " +
			"a field\n\tof width w with fill character fc");
	    }
	    public void execute(LineScanner ls) {
		int n = ls.readInt();
		int w = ls.readInt();
		char fc = ls.readChar();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.hexadecimal(n, w, fc) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("hb");
		arguments = new String("n w");
		brief = new String("displays a hexadecimal value");
		full = new String("displays the hexadecimal value of n in " +
			"a field\n\tof width w with blank fill characters");
	    }
	    public void execute(LineScanner ls) {
		int n = ls.readInt();
		int w = ls.readInt();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.hexadecimal(n, w) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("oc");
		arguments = new String("n w fc");
		brief = new String("displays an octal value");
		full = new String("displays the octal value of n in a " +
			"field\n\tof width w with fill character fc");
	    }
	    public void execute(LineScanner ls) {
		int n = ls.readInt();
		int w = ls.readInt();
		char fc = ls.readChar();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.octal(n, w, fc) + "|");
		}
	    }
	});

	commandTable.add(new Command() {
	    {
		name = new String("ob");
		arguments = new String("n w");
		brief = new String("displays an octal value");
		full = new String("displays the octal value of n in a " +
			"field\n\tof width w with blank fill characters");
	    }
	    public void execute(LineScanner ls) {
		int n = ls.readInt();
		int w = ls.readInt();
		ls.readEnd();
		if (ls.errorCount() == 0) {
		    System.out.println("|" +
			    Formatting.octal(n, w) + "|");
		}
	    }
	});

    }  // public void addCommands()

    /** If this program is executed with no command line argument then it
     *  executes commands entered from the terminal.  If this program is
     *  executed with a single command-line argument then that argument
     *  is interpreted as a file name.  The program attempts to open the
     *  named file and execute the commands in it.  If the open fails, or
     *  if there is more than one command-line argument, then the program
     *  terminates with an error message.
     */
    public static void main(String[] args)
    throws FileNotFoundException, IOException {
	Tester tester = new FormattingTester();
	tester.openStream(args);
	tester.addCommands();
	tester.doCommands();
    }  // public static main(String[])

}  // public class FormattingTester

[an error occurred while processing this directive]