Search in sources :

Example 1 with JarContents

use of the.bytecode.club.bytecodeviewer.bootloader.resource.jar.contents.JarContents in project bytecode-viewer by Konloch.

the class ExternalLibrary method load.

/* (non-Javadoc)
     * @see the.bytecode.club.bytecodeviewer.loadermodel.ExternalResource#load()
     */
@Override
public JarContents<ClassNode> load() throws IOException {
    JarContents<ClassNode> contents = new JarContents<>();
    JarURLConnection con = (JarURLConnection) getLocation().openConnection();
    JarFile jar = con.getJarFile();
    Enumeration<JarEntry> entries = jar.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        try (InputStream is = jar.getInputStream(entry)) {
            byte[] bytes = read(is);
            if (entry.getName().endsWith(".class")) {
                ClassNode cn = create(bytes);
                contents.getClassContents().add(cn);
            } else {
                JarResource resource = new JarResource(entry.getName(), bytes);
                contents.getResourceContents().add(resource);
            }
        }
    }
    return contents;
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) JarURLConnection(java.net.JarURLConnection) InputStream(java.io.InputStream) JarResource(the.bytecode.club.bytecodeviewer.bootloader.resource.jar.JarResource) JarContents(the.bytecode.club.bytecodeviewer.bootloader.resource.jar.contents.JarContents) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry)

Aggregations

InputStream (java.io.InputStream)1 JarURLConnection (java.net.JarURLConnection)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 ClassNode (org.objectweb.asm.tree.ClassNode)1 JarResource (the.bytecode.club.bytecodeviewer.bootloader.resource.jar.JarResource)1 JarContents (the.bytecode.club.bytecodeviewer.bootloader.resource.jar.contents.JarContents)1