Example usage for org.apache.commons.compress.archivers.jar JarArchiveInputStream getNextJarEntry

List of usage examples for org.apache.commons.compress.archivers.jar JarArchiveInputStream getNextJarEntry

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.jar JarArchiveInputStream getNextJarEntry.

Prototype

public JarArchiveEntry getNextJarEntry() throws IOException 

Source Link

Usage

From source file:divconq.mod.JarLibLoader.java

public JarLibLoader(String name) {
    super(name);/*from ww  w . jav a  2  s . co  m*/

    JarArchiveInputStream stream = null;

    try {
        InputStream theFile = new FileInputStream(this.name);
        stream = new JarArchiveInputStream(theFile);

        JarArchiveEntry entry = stream.getNextJarEntry();

        while (entry != null) {
            if (!entry.isDirectory()) {
                //if (entry.getName().endsWith("Container.class"))
                //   System.out.println("at cont");

                int esize = (int) entry.getSize();

                if (esize > 0) {
                    int eleft = esize;
                    byte[] buff = new byte[esize];
                    int offset = 0;

                    while (offset < esize) {
                        int d = stream.read(buff, offset, eleft);
                        offset += d;
                        eleft -= d;
                    }

                    this.entries.put("/" + entry.getName(), buff);
                }
            }

            entry = stream.getNextJarEntry();
        }
    } catch (Exception x) {
        // TODO logging
        System.out.println(x);
    } finally {
        try {
            if (stream != null)
                stream.close();
        } catch (Exception x) {

        }
    }
}

From source file:es.jamisoft.comun.utils.compression.Jar.java

private void unjar(InputStream is, String outputDirectory) throws IOException {
    JarArchiveInputStream jis = new JarArchiveInputStream(is);
    JarArchiveEntry jarEntry = null;//from w  w w .  j  a v  a 2 s . c om
    byte buffer[] = new byte[1024];
    int readCount = 0;

    if (!outputDirectory.endsWith(File.separator)) {
        outputDirectory = outputDirectory + File.separator;
    }

    do {
        if ((jarEntry = jis.getNextJarEntry()) == null) {
            break;
        }

        if (jarEntry.isDirectory()) {
            File file = new File(outputDirectory + jarEntry.getName());

            if (!file.exists()) {
                file.mkdir();
            }
        } else {
            FileOutputStream fos = new FileOutputStream(outputDirectory + jarEntry.getName());

            while ((readCount = jis.read(buffer)) != -1) {
                fos.write(buffer, 0, readCount);
            }

            fos.close();
        }
    } while (true);

    jis.close();
}

From source file:org.apache.openejb.maven.plugin.customizer.monkey.jar.JarPatcher.java

private int unjar(final File exploded, final File from) {
    int method = -1;

    JarArchiveInputStream stream = null;
    try {/*ww w  . j a va 2 s .  co m*/
        stream = new JarArchiveInputStream(new FileInputStream(from));
        JarArchiveEntry entry;
        while ((entry = stream.getNextJarEntry()) != null) {
            final File archiveEntry = new File(exploded, entry.getName());
            archiveEntry.getParentFile().mkdirs();
            if (entry.isDirectory()) {
                archiveEntry.mkdir();
                continue;
            }

            final OutputStream out = new FileOutputStream(archiveEntry);
            IOUtils.copy(stream, out);
            out.close();
            if (method < 0) {
                method = entry.getMethod();
            }
        }
    } catch (final IOException e) {
        throw new IllegalArgumentException(e);
    } finally {
        IO.close(stream);
    }

    return method;
}