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 b[]) throws IOException 

Source Link

Document

Reads some number of bytes from the input stream and stores them into the buffer array b.

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 .j a v  a2s .  co  m
    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();
}