How can I get only the classes that implement an interface MyInterface
without iterating through all JarEntry
s in a .jar file?
JarFile jar = new JarFile("jar/test.jar");
JarEntry entry = jar.getJarEntry("ClassName.class");
InputStream is = jar.getInputStream(entry);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
int nextValue = is.read();
while (-1 != nextValue) {
byteStream.write(nextValue);
nextValue = is.read();
}
classByte = byteStream.toByteArray();
Class myClass = defineClass("ClassName", classByte, 0, classByte.length, null);
...
// AVoid
if (MyInterface.class.isAssignableFrom(myClass)) {
...
}
Aucun commentaire:
Enregistrer un commentaire