コード例 #1
0
ファイル: Installer.java プロジェクト: suever/CTP
 private Hashtable<String, String> getJarManifestAttributes(String path) {
   Hashtable<String, String> h = new Hashtable<String, String>();
   JarInputStream jis = null;
   try {
     cp.appendln(Color.black, "Looking for " + path);
     InputStream is = getClass().getResourceAsStream(path);
     if (is == null) {
       if (!path.endsWith("/MIRC.jar")) {
         cp.appendln(Color.red, "...could not find it.");
       } else {
         cp.appendln(
             Color.black,
             "...could not find it. [OK, this is a " + programName + " installation]");
       }
       return null;
     }
     jis = new JarInputStream(is);
     Manifest manifest = jis.getManifest();
     h = getManifestAttributes(manifest);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   if (jis != null) {
     try {
       jis.close();
     } catch (Exception ignore) {
     }
   }
   return h;
 }
コード例 #2
0
ファイル: Jar2Jad.java プロジェクト: kazuyakuza/wh40kh
  public static boolean extractJarDir(String jarfile, String outfile) throws Exception {
    long filesize = new File(jarfile).length();
    JarInputStream jar = new JarInputStream(new FileInputStream(jarfile));
    // while (true) {
    //	JarEntry jarentry = (JarEntry)jar.getNextJarEntry();
    //	if (jarentry==null) break;
    //	String maindir = jarentry.getName();
    //	// get rid of "./" and "/" prefix
    //	if (maindir.startsWith("."))
    //		maindir = maindir.substring(1);
    //	if (maindir.startsWith(File.separator))
    //		maindir = maindir.substring(1);
    //	// Find manifest
    //	System.out.println(maindir);
    //	if (maindir.equals("META-INF/MANIFEST.MF")) {
    //		java.io.InputStream ins = jar;

    java.io.FileOutputStream outs = new java.io.FileOutputStream(outfile);
    Manifest man = jar.getManifest();
    if (man == null) return false;
    man.write(outs);
    byte[] buf = ("MIDlet-Jar-Size: " + filesize).getBytes();
    outs.write(buf, 0, buf.length);
    outs.close();
    //		// copy buffered (is a lot faster than one byte at a time)
    //		byte[] buf = new byte[8192];
    //		int total_bytes=0;
    //		while (true) {
    //			//outs.write(ins.read());
    //			int len = ins.read(buf);
    //			if (len < 0) break;
    //			outs.write(buf,0,len);
    //			total_bytes += len;
    //		}
    //		buf = ("MIDlet-Jar-Size: "+total_bytes).getBytes();
    //		outs.write(buf,0,buf.length);
    //		outs.close();
    //		//ins.close();
    //	}
    // }
    // return false;
    // remove empty lines from the generated jad which may have been
    // introduced by manifest write.
    // some systems have trouble with empty lines
    List<String> lines = new ArrayList<String>();
    BufferedReader in = new BufferedReader(new FileReader(outfile));
    while (true) {
      String line = in.readLine();
      if (line == null) break;
      lines.add(line);
    }
    in.close();
    PrintWriter outp = new PrintWriter(outfile);
    for (String s : lines) {
      if (s.trim().equals("")) continue;
      outp.println(s);
    }
    outp.close();
    return true;
  }