1 56 57 import java.util.zip.ZipFile ; 58 import java.util.zip.ZipEntry ; 59 60 import java.io.IOException ; 61 import java.io.InputStream ; 62 import java.io.FileInputStream ; 63 64 import java.util.HashMap ; 65 import java.util.Enumeration ; 66 67 81 public final class Ident { 82 83 84 private final static int KDELIM = '$'; 85 86 87 private final static int VDELIM = ':'; 88 89 90 private final static String [] rcsTags = { 91 "Author", 93 "Date", 95 "Header", 99 "Id", 102 "Locker", 105 "Log", 108 "Name", 110 "RCSfile", 112 "Revision", 114 "Source", 116 "State" }; 119 120 121 private final static HashMap tagMap; 122 123 public static void main(String args[]) throws IOException { 124 if (args.length > 0 ) { 125 for (int i = 0; i < args.length; i++) { 126 System.out.println(args[i]+":"); 127 if (isZip(args[i])) { 128 ZipFile zipFile = new ZipFile (args[i]); 129 Enumeration entries = zipFile.entries(); 130 while (entries.hasMoreElements()) { 131 ZipEntry ze = (ZipEntry )entries.nextElement(); 132 System.out.println(" ->"+ze.getName()+"<-"); 133 scan(zipFile.getInputStream(ze)); 134 } 135 } else { 136 FileInputStream fis = new FileInputStream (args[i]); 137 scan(fis); 138 } 139 } 140 } else { 141 printUsage(); 142 } 143 } 144 145 private static void printUsage() { 146 System.out.println( 147 "This program prints RCS information about a class file."); 148 System.out.println("Usage: java Ident [classfile.class | jarfile.jar]"); 149 } 150 151 private static boolean isZip(String fileName) { 152 return fileName.endsWith(".jar") || 153 fileName.endsWith(".zip"); 154 } 155 156 private static void scan(InputStream is) throws IOException { 157 int i = 0; 158 StringBuffer sb = new StringBuffer (); 159 160 boolean inTag = false; 161 boolean validTag = false; 162 163 while ((i = is.read()) != -1) { 164 165 if (i == KDELIM) { 167 if (inTag) { 169 if (validTag) { 170 System.out.println(" $"+sb.toString()+"$"); 171 } 172 validTag = inTag = false; 173 sb = new StringBuffer (); 174 } else { 175 inTag = true; 176 continue; 177 } 178 } else if (i == VDELIM) { 179 if (inTag && !validTag) { 180 String tag = sb.toString(); 181 if (tagMap.get(tag) == null) { 182 inTag = false; 184 validTag = false; 185 sb = new StringBuffer (); 186 } else { 187 validTag = true; 188 } 189 } 190 } 191 192 if (inTag) { 193 sb.append((char)i); 194 } 195 } 196 } 197 198 static { 199 tagMap = new HashMap (); 200 for (int i = 0; i < rcsTags.length; i++) { 201 tagMap.put(rcsTags[i],rcsTags[i]); 202 } 203 } 204 } 205
| Popular Tags
|