import java.io.*; import java.util.*; public class Text { static public void main(String args[]) { if (args.length != 3) throw new IllegalArgumentException("Text requires 3 arguments: TailInt StringToReplace ReplacementString"); InputStreamReader in1 = new InputStreamReader(System.in); OutputStreamWriter out3 = new OutputStreamWriter(System.out); PipedReader in2 = new PipedReader(); PipedWriter out1 = new PipedWriter(); try { out1.connect(in2); } catch (IOException e) { System.out.println(e); } PipedReader in3 = new PipedReader(); PipedWriter out2 = new PipedWriter(); try { out2.connect(in3); } catch (IOException e) { System.out.println(e); } int initReadBufSize = 100; int initWriteBufSize = 100; // pass in the argument for tail on the command line int i1 = Integer.parseInt(args[0]); // Tail is the class that implements the file read function Tail t1 = new Tail(i1); FilterImpl tail = new FilterImpl(in1, out1, initReadBufSize, initWriteBufSize, t1); // give the computation thread a hook back into the Filter t1.setFilter(tail); // pass in the strings to replace on the command line String s1 = args[1]; String s2 = args[2]; // Replace is the class that implements the string replacement Replace r1 = new Replace(s1, s2); FilterImpl replace = new FilterImpl(in2, out2, initReadBufSize, initWriteBufSize, r1); // give the computation thread a hook back into the Filter r1.setFilter(replace); // Unique is the class that implements removing duplicate lines Unique u1 = new Unique(); FilterImpl unique = new FilterImpl(in3, out3, initReadBufSize, initWriteBufSize, u1); // give the computation thread a hook back into the Filter u1.setFilter(unique); replace.startFilter(); unique.startFilter(); tail.startFilter(); } }