/Users/lyon/j4p/src/rtf/Java2Rtf.java
|
1 /**
2 Christopher Scaglione and Doug Lyon
3 SW409
4 Midterm
5 */
6
7 package rtf;
8
9 import futils.Futil;
10 import futils.ReaderUtil;
11 import futils.WriterUtil;
12
13 import java.io.BufferedReader;
14 import java.io.BufferedWriter;
15 import java.io.File;
16
17 public class Java2Rtf {
18
19 public static void main(String args[]) {
20 if (args.length < 2) {
21 runGui();
22 return;
23 }
24 if (args.length == 2) {
25 processTwoArgs(args);
26 return;
27 }
28 processManyArgs(args);
29
30 }
31
32 private static void processManyArgs(String args[]) {
33 for (int i = 0; i < args.length; i++) {
34 BufferedWriter bw = WriterUtil.getBufferedWriter(
35 new File(args[i] + ".rtf"));
36
37 BufferedReader br =
38 ReaderUtil.getBufferedReader(new File(args[i]));
39 System.out.println("processing file:" + args[i]);
40 javaToRtf(br, bw);
41 }
42 }
43
44 private static void processTwoArgs(String[] args) {
45 System.out.println("files:" + args[0] + " " + args[1]);
46 BufferedReader br = ReaderUtil.getBufferedReader(new File(args[0]));
47 BufferedWriter bw = WriterUtil.getBufferedWriter(new File(args[1]));
48 javaToRtf(br, bw);
49 }
50
51 public static void javaToRtf(BufferedReader br, BufferedWriter bw) {
52 processFileNoClose(br, bw);
53 close(bw);
54 System.out.println("Done!");
55 }
56
57 private static void close(BufferedWriter bw) {
58 WriterUtil.close(bw);
59 }
60
61 private static void processFileNoClose(BufferedReader br, BufferedWriter bw) {
62 RtfUtil ru = new RtfUtil();
63 ru.javaToRtf(br, bw);
64 }
65
66 public static void runGui() {
67 File f = Futil.getReadFile("select java file");
68 BufferedWriter bw = WriterUtil.getBufferedWriter("enter the output file");
69 BufferedReader br = ReaderUtil.getBufferedReader(f);
70 javaToRtf(br, bw);
71 }
72 }
73