
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 {
    private static void usage()
    {
        System.err.println("Usage: TestApp <algorithm> <input file> [-o <output file>]");
    }

    public static void main(String [] args) throws Throwable {
	if (args.length < 2) {
            usage();
            return;
        }

	Class stemClass = Class.forName("org.tartarus.snowball.ext." +
					args[0] + "Stemmer");
        SnowballStemmer stemmer = (SnowballStemmer) stemClass.newInstance();

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

	StringBuffer input = new StringBuffer();

        OutputStream outstream;

	if (args.length > 2) {
            if (args.length == 4 && args[2].equals("-o")) {
                outstream = new FileOutputStream(args[3]);
            } else {
                usage();
                return;
            }
	} else {
	    outstream = System.out;
	}
	Writer output = new OutputStreamWriter(outstream);
	output = new BufferedWriter(output);

	int character;
	while ((character = reader.read()) != -1) {
	    char ch = (char) character;
	    if (Character.isWhitespace(ch)) {
		stemmer.setCurrent(input.toString());
		stemmer.stem();
		output.write(stemmer.getCurrent());
		output.write('\n');
		input.delete(0, input.length());
	    } else {
		input.append(ch < 127 ? Character.toLowerCase(ch) : ch);
	    }
	}
	output.flush();
    }
}

@@ -63,54 +63,8 @@
 od;%0A
-import java.io.Reader;%0Aimport java.io.Writer;%0A
 impo
@@ -145,32 +145,93 @@
 ileInputStream;%0A
+import java.io.FileOutputStream;%0Aimport java.io.InputStream;%0A
 import java.io.I
@@ -240,32 +240,61 @@
 utStreamReader;%0A
+import java.io.OutputStream;%0A
 import java.io.O
@@ -323,36 +323,30 @@
 ort java.io.
-OutputStream
+Reader
 ;%0Aimport jav
@@ -350,32 +350,22 @@
 java.io.
-FileOutputStream
+Writer
 ;%0A%0Apubli
@@ -475,16 +475,17 @@
 orithm%3E 
+%5B
 %3Cinput f
@@ -488,16 +488,17 @@
 ut file%3E
+%5D
  %5B-o %3Cou
@@ -832,166 +832,187 @@
 ;%0A%0A%09
-Reader reader;%0A%09reader = new InputStreamReader(new FileInputStream(args%5B1%5D));%0A%09reader = new BufferedReader(reader);%0A%0A%09StringBuffer input = new StringBuffer();
+int arg = 1;%0A%0A%09InputStream instream;%0A%09if (args.length %3E arg && !args%5Barg%5D.equals(%22-o%22)) %7B%0A%09    instream = new FileInputStream(args%5Barg++%5D);%0A%09%7D else %7B%0A%09    instream = System.in;%0A%09%7D
 %0A%0A  
@@ -1041,17 +1041,16 @@
 stream;%0A
-%0A
 %09if (arg
@@ -1060,17 +1060,19 @@
 ength %3E 
-2
+arg
 ) %7B%0A    
@@ -1099,22 +1099,31 @@
 gth 
-== 4 && 
+!= arg + 2 %7C%7C !
 args%5B
-2
+arg
 %5D.eq
@@ -1156,51 +1156,20 @@
     
-outstream = new FileOutputStream(args%5B3%5D);%0A
+usage();%0A   
     
@@ -1176,24 +1176,24 @@
         
-%7D else %7B
+ return;
 %0A       
@@ -1201,100 +1201,195 @@
     
+%7D%0A%09
     
-usage();%0A                return;%0A            %7D%0A%09%7D else %7B%0A%09    outstream = System.out;%0A%09%7D
+outstream = new FileOutputStream(args%5Barg + 1%5D);%0A%09%7D else %7B%0A%09    outstream = System.out;%0A%09%7D%0A%0A%09Reader reader = new InputStreamReader(instream);%0A%09reader = new BufferedReader(reader);%0A
 %0A%09Wr
@@ -1472,24 +1472,66 @@
 r(output);%0A%0A
+%09StringBuffer input = new StringBuffer();%0A
 %09int charact

Allow TestApp.java to read input from stdin