/Users/lyon/j4p/src/security/CertUtils.java
|
1 package security;
2
3 import java.io.BufferedReader;
4 import java.io.BufferedWriter;
5 import java.io.IOException;
6
7
8
9 /**
10 * DocJava, Inc. User: lyon Date: Aug 3, 2004
11 * Time: 10:07:24 AM
12 */
13 public class CertUtils {
14
15
16 public final static int LINE_LENGTH = 76;
17 public final static String START = "BEGIN PKCS";
18 public final static String END = "END PKCS";
19
20 public static void main(String[] args)
21 throws IOException {
22
23 cleanThawtes();
24 System.out.println("done!");
25
26 }
27
28 public static void cleanThawtes()
29 throws IOException {
30 BufferedReader r = new BufferedReader(
31 futils.Futil.getFileReader(
32 "select a Thawte file"));
33 BufferedWriter w = new BufferedWriter(
34 futils.WriterUtil.getFileWriter(
35 "enter output file"));
36 String line;
37 line = scanUntilStart(r);
38 w.write(line);
39 w.newLine();
40 int outIndex = 0;
41 while ((line = r.readLine()) != null) {
42 if (line.indexOf(END) != -1) {
43 if (outIndex != 0)
44 w.newLine();
45 w.write(line);
46 break;
47 }
48 outIndex =
49 packOutputTo76Chars(line,
50 w,
51 outIndex);
52 }
53 w.close();
54 r.close();
55 }
56
57 private static int packOutputTo76Chars(
58 String line,
59 BufferedWriter w,
60 int outIndex) throws IOException {
61 int inIndex;
62 inIndex = 0;
63 while (inIndex < line.length()) {
64 w.write(line.charAt(inIndex));
65 outIndex++;
66 if (outIndex == LINE_LENGTH) {
67 w.newLine();
68 outIndex = 0;
69 }
70 inIndex++;
71 }
72 return outIndex;
73 }
74 /**
75 * Scan the buffered reader until the
76 * start keyword is found.
77 * @param r
78 * @return
79 * @throws IOException
80 */
81 private static String scanUntilStart(
82 BufferedReader r) throws IOException {
83 String line;
84 while ((line = r.readLine()).indexOf(
85 START) ==
86 -1)
87 ;
88 return line;
89 }
90
91 }
92