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

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

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

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  .jav a2  s.  com*/
    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:divconq.mod.JarLibLoader.java

public JarLibLoader(String name) {
    super(name);/*from  w  w w  .java 2 s.  c o 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) {

        }
    }
}