
package org.tartarus.snowball;

import java.lang.reflect.Method;
import java.io.Reader;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.FileOutputStream;

public class TestApp {
    public static void main(String [] args) throws Throwable {
	Class stemClass = Class.forName("org.tartarus.snowball.ext." +
					args[0] + "Stemmer");
        SnowballProgram stemmer = (SnowballProgram) stemClass.newInstance();
	Method stemMethod = stemClass.getMethod("stem", new Class[0]);

	Reader reader;
	reader = new InputStreamReader(new FileInputStream(args[1]));
	reader = new BufferedReader(reader);

	StringBuffer input = new StringBuffer();

        OutputStream outstream;

	if (args.length > 2 && args[2].equals("-o")) {
	    outstream = new FileOutputStream(args[3]);
	} else if (args.length == 2) {
	    System.err.println("Usage: TestApp <input file> [-o <output file>]");
	    return;
	} else {
	    outstream = System.out;
	}
	Writer output = new OutputStreamWriter(outstream);
	output = new BufferedWriter(output);

	int repeat = 1;
	if (args.length > 4) {
	    repeat = Integer.parseInt(args[4]);
	}

	Object [] emptyArgs = new Object[0];
	int character;
	while ((character = reader.read()) != -1) {
	    char ch = (char) character;
	    if (Character.isWhitespace((char) ch)) {
		if (input.length() > 0) {
		    stemmer.setCurrent(input.toString());
		    for (int i = repeat; i != 0; i--) {
			stemMethod.invoke(stemmer, emptyArgs);
		    }
		    output.write(stemmer.getCurrent());
		    output.write('\n');
		    input.delete(0, input.length());
		}
	    } else {
		input.append(Character.toLowerCase(ch));
	    }
	}
	output.flush();
    }
}

@@ -363,65 +363,276 @@
    p
-ublic static void main(String %5B%5D args) throws Throwable %7B
+rivate static void usage()%0A    %7B%0A        System.err.println(%22Usage: TestApp %3Calgorithm%3E %3Cinput file%3E %5B-o %3Coutput file%3E%5D%22);%0A    %7D%0A%0A    public static void main(String %5B%5D args) throws Throwable %7B%0A%09if (args.length %3C 2) %7B%0A            usage();%0A            return;%0A        %7D%0A
 %0A%09Cl
@@ -1075,16 +1075,52 @@
 ngth %3E 2
+) %7B%0A            if (args.length == 4
  && args
@@ -1135,25 +1135,36 @@
 ls(%22-o%22)) %7B%0A
-%09
+            
     outstrea
@@ -1202,127 +1202,91 @@
 %5D);%0A
-%09%7D else if (args.length == 2) %7B%0A%09    System.err.println(%22Usage: TestApp %3Cinput file%3E %5B-o %3Coutput file%3E%5D%22);%0A%09    return;
+            %7D else %7B%0A                usage();%0A                return;%0A            %7D
 %0A%09%7D 

Correct the tests for usage of the java test program.