1 package SnowMailClient.gnupg.LineProcessors; 2 3 import SnowMailClient.gnupg.model.*; 4 import java.util.*; 5 import java.io.*; 6 7 public class KeySearchResultProcessor implements LineProcessor 8 { 9 private final Vector<KeyIDFromSearchResult> keys = new Vector<KeyIDFromSearchResult>(); 10 private KeyIDFromSearchResult actual = null; 11 12 public KeySearchResultProcessor() 13 { 14 15 } 17 public Vector<KeyIDFromSearchResult> getKeyIDs() { return keys; } 18 19 public void processLine(String _line) 20 { 21 String line = _line.trim(); 22 if(line.startsWith("gpg:")) 23 { 24 } 27 else if(line.startsWith("(")) 28 { 29 actual = new KeyIDFromSearchResult(); 30 keys.addElement(actual); 31 int pos = line.indexOf(")"); 32 if(pos>0) line = line.substring(pos+1).trim(); 33 actual.addAddress(line); 34 } 35 else if(line.indexOf("@")>0) 36 { 37 actual.addAddress(line); 38 } 39 else 40 { 41 actual.parseIDLine(line); 42 } 43 44 } 45 46 47 public String toString() 48 { 49 StringBuffer sb = new StringBuffer (); 50 for(KeyIDFromSearchResult k: keys) 51 { 52 sb.append(""+k+"\n"); 53 } 54 return sb.toString(); 55 } 56 57 58 59 public static void main(String [] a) 60 { 61 KeySearchResultProcessor kr = new KeySearchResultProcessor(); 62 kr.test(); 63 } 64 65 private void test() 66 { 67 try 68 { 69 70 FileInputStream fis = new FileInputStream("c:/temp/kex.txt"); 71 BufferedReader r= new BufferedReader(new InputStreamReader(fis)); 72 String line; 73 while((line=r.readLine())!=null) 74 { 75 processLine(line); 76 } 77 System.out.println(""+this); 78 79 } 80 catch(Exception e) 81 { 82 e.printStackTrace(); 83 } 84 } 85 86 87 } 89 90 | Popular Tags |