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

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

Introduction

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

Prototype

public int read(byte[] buffer, int start, int length) throws IOException 

Source Link

Usage

From source file:divconq.mod.JarLibLoader.java

public JarLibLoader(String name) {
    super(name);/*ww w  .j a  va  2 s.  com*/

    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) {

        }
    }
}