1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
package utils;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.log4j.Logger;
public class ReadClass {
public static void main(String[] args) {
readJarFile("/home/Mike/oracle.jar", "oracle.core.lmx.CoreException");
}
public static String readJarFile(String fichier, String name) {
Logger log = Logger.getLogger("jarfile");
try {
//Je recherche ma classe dans le fichier JAR
JarFile jf = new JarFile(fichier);
Enumeration e = jf.entries();
int i = 0;
JarEntry je = null;
for(i=0;e.hasMoreElements() && i<1000;i++) {
je = (JarEntry)e.nextElement();
if(je.toString().replaceAll("/",".").replace(".class","").equals(name)) {
i = 1001;
}
}
// Je commence à lire le contenu, c'est là où j'ai un problème...
InputStream is = jf.getInputStream(je);
Byte lu = 0;
String contenu = "";
char c = ' ';
i = 0;
while((lu=(byte)is.read()) != -1) {
c = (char)(int)lu;
contenu += c;
i++;
}
System.out.println("JE-FILE : "+je.getCompressedSize() );
System.out.println("CONTENU : "+i);
return contenu;
}
catch(Exception e) {
log.fatal(e);
}
return null;
}
} |
Partager