Example #1
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    if (args == null) {
      System.err.println("Usage: input_jar_file output_root_dir url_dir");
      System.err.println("Usage: --compare bld# bld#");
      System.exit(1);
    } else if (args[0].endsWith("compare")) {
      try {
        URL url1 = new URL(VISAGE.replace(BLDTAG, args[1]));
        URL url2 = new URL(VISAGE.replace(BLDTAG, args[2]));
        Hashtable<String, PkgEntry> tbl1 = readJarFile(url1);
        Hashtable<String, PkgEntry> tbl2 = readJarFile(url2);
        dumpToFile(args[1], args[2], System.out, tbl1, tbl2);
      } catch (MalformedURLException ex) {
        Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex);
      }
    } else {
      try {
        String inputJarFile = args[0];
        String outputRootDir = args[1];
        String urlDir = args[2];
        Hashtable<String, PkgEntry> tbl = readJarFile(new File(inputJarFile));

        // Plot information for all packages
        dumpToFileAllPackages(tbl, outputRootDir, urlDir);
        JarStat js = getTotals(new File(inputJarFile));
        File outputFile = new File(outputRootDir + "/staticsizes." + "jar-size-compressed");
        js.printSize(outputFile, true, urlDir);
        outputFile = new File(outputRootDir + "/staticsizes." + "jar-size-uncompressed");
        js.printSize(outputFile, false, urlDir);
        // Plot information for single package
        for (String key : tbl.keySet()) {
          outputFile = new File(outputRootDir + "/staticsizes." + key);
          outputFile.createNewFile();
          FileOutputStream ostream = new FileOutputStream(outputFile);
          PrintWriter pw = new PrintWriter(new OutputStreamWriter(ostream));
          pw.printf("YVALUE=%s\n", tbl.get(key).getSize() / 1024);
          pw.flush();
          pw.close();
        }
      } catch (IOException ex) {
        Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex);
        System.exit(1);
      }
    }
    System.exit(0);
  }
Example #2
0
 private static JarStat getTotals(File file) {
   ZipFile zf = null;
   JarStat js = null;
   try {
     js = new JarStat(file);
     zf = new ZipFile(file);
     for (ZipEntry ze : Collections.list(zf.entries())) {
       js.addSizes(zf, ze);
     }
   } catch (ZipException ex) {
     Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex);
   } catch (IOException ex) {
     Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     if (zf != null) {
       try {
         zf.close();
       } catch (IOException ex) {
       }
     }
   }
   return js;
 }