Example usage for java.util.zip ZipInputStream close

List of usage examples for java.util.zip ZipInputStream close

Introduction

In this page you can find the example usage for java.util.zip ZipInputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:Main.java

public static byte[] unZip(byte[] bContent) throws IOException {
    byte[] b = null;
    try {/* w w w  .  j a  v a2s .  c  om*/
        ByteArrayInputStream bis = new ByteArrayInputStream(bContent);
        ZipInputStream zip = new ZipInputStream(bis);

        while (zip.getNextEntry() != null) {
            byte[] buf = new byte[1024];
            int num = -1;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            while ((num = zip.read(buf, 0, buf.length)) != -1) {
                baos.write(buf, 0, num);
            }
            b = baos.toByteArray();
            baos.flush();
            baos.close();
        }
        zip.close();
        bis.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return b;
}

From source file:Main.java

public static void unzip(String zipFilePath, String fileName) {

    try {//from ww  w  . ja v  a  2s  . c  o  m
        FileInputStream fin = new FileInputStream(zipFilePath);
        ZipInputStream zin = new ZipInputStream(fin);

        do {
            // no-op
        } while (!zin.getNextEntry().getName().equals(fileName));

        OutputStream os = new FileOutputStream(fileName);

        byte[] buffer = new byte[1024];
        int length;

        //read the entry from zip file and extract it to disk
        while ((length = zin.read(buffer)) > 0) {
            os.write(buffer, 0, length);
        }
        os.close();
        zin.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:com.nuvolect.securesuite.util.OmniZip.java

public static List<String> getFilesList(OmniFile zipOmni) {

    ZipInputStream zis = new ZipInputStream(zipOmni.getFileInputStream());

    List<String> arrayList = new ArrayList<>();

    ZipEntry entry = null;//from   w w w  . j a  va 2 s  . c o  m
    try {
        while ((entry = zis.getNextEntry()) != null) {

            arrayList.add(entry.getName());
        }
        zis.close();

    } catch (IOException e) {
        LogUtil.logException(LogUtil.LogType.OMNI_ZIP, e);
    }

    return arrayList;
}

From source file:nl.clockwork.common.util.Utils.java

public static byte[] unzip(byte[] content) throws IOException {
    int BUFFER_SIZE = 2048;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(content));
    ZipEntry entry = zin.getNextEntry();
    if (entry != null) {
        int count;
        byte buffer[] = new byte[BUFFER_SIZE];
        BufferedOutputStream bout = new BufferedOutputStream(out, BUFFER_SIZE);
        while ((count = zin.read(buffer, 0, BUFFER_SIZE)) != -1)
            bout.write(buffer, 0, count);
        bout.flush();//from  www  .ja v  a  2  s  . co  m
        bout.close();
        zin.close();
    }
    return out.toByteArray();
}

From source file:Main.java

/**
 * Decompresses a given byte array that is a compressed folder.
 * //  w ww.j a v  a2  s.com
 * @param folderAsCompressedArray to decompress
 * @param unzippedLocation where the decompressed folder should be
 * @throws IOException e
 * @throws FileNotFoundException e
 */
public static void decompressFolderByteArray(byte[] folderAsCompressedArray, File unzippedLocation)
        throws IOException, FileNotFoundException {
    ZipInputStream zipFile = new ZipInputStream(new ByteArrayInputStream(folderAsCompressedArray));
    ZipEntry ze = null;
    final int minusOne = -1;
    while ((ze = zipFile.getNextEntry()) != null) {
        FileOutputStream fout = new FileOutputStream(
                new File(unzippedLocation, ze.getName()).getAbsolutePath());
        for (int c = zipFile.read(); c != minusOne; c = zipFile.read()) {
            fout.write(c);
        }
        zipFile.closeEntry();
        fout.close();
    }
    zipFile.close();
}

From source file:org.apache.jackrabbit.oak.plugins.segment.SegmentGraphTest.java

private static void unzip(InputStream is, File target) throws IOException {
    ZipInputStream zis = new ZipInputStream(is);
    try {/*www  .  j ava2s  .  c  om*/
        for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) {
            OutputStream out = new FileOutputStream(new File(target, entry.getName()));
            try {
                IOUtils.copy(zis, out);
            } finally {
                out.close();
            }
        }
    } finally {
        zis.close();
    }
}

From source file:com.nuvolect.securesuite.util.OmniZip.java

public static List<String> getDirsList(OmniFile zipOmni) {

    ZipInputStream zis = new ZipInputStream(zipOmni.getFileInputStream());

    List<String> arrayList = new ArrayList<>();

    ZipEntry entry = null;//from   ww  w. jav  a  2  s.  com
    try {
        while ((entry = zis.getNextEntry()) != null) {

            if (entry.isDirectory())
                arrayList.add(entry.getName());
        }
        zis.close();

    } catch (IOException e) {
        LogUtil.logException(LogUtil.LogType.OMNI_ZIP, e);
    }

    return arrayList;
}

From source file:Main.java

private static List<String> extractClassNames(String path) throws IOException, NoSuchMethodException,
        SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    addToClassPath(path);//w w  w.  ja va 2s  .c o m
    List<String> classNames = new ArrayList<String>();
    ZipInputStream zipStream = new ZipInputStream(new FileInputStream(path));
    try {
        for (ZipEntry entry = zipStream.getNextEntry(); entry != null; entry = zipStream.getNextEntry()) {
            if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
                String className = entry.getName().replace('/', '.');
                classNames.add(className.substring(0, className.length() - ".class".length()));
            }
        }
        return classNames;
    } finally {
        zipStream.close();
    }
}

From source file:org.dhatim.ect.EdiConvertionTool.java

/**
 * Write an EDI Mapping Model configuration set from a UN/EDIFACT
 * specification./*from  ww w.java  2s .co m*/
 *
 * @param specification The UN/EDIFACT specification zip file.
 * @param modelSetOutFolder The output folder for the generated EDI Mapping Model configuration set.
 * @param urn The URN for the EDI Mapping model configuration set.
 * @throws IOException Error writing Mapping Model configuration set.
 */
public static void fromUnEdifactSpec(ZipInputStream specification, File modelSetOutFolder, String urn,
        boolean useShortName) throws IOException {
    try {
        fromSpec(new UnEdifactSpecificationReader(specification, true, useShortName), modelSetOutFolder, urn);
    } finally {
        specification.close();
    }
}

From source file:org.dhatim.ect.EdiConvertionTool.java

/**
 * Write an EDI Mapping Model configuration set from a UN/EDIFACT
 * specification.//from   w  w  w  .  java 2s. c  o  m
 *
 * @param specification The UN/EDIFACT specification zip file.
 * @param modelSetOutStream The output zip stream for the generated EDI Mapping Model configuration set.
 * @param urn The URN for the EDI Mapping model configuration set.
 * @throws IOException Error writing Mapping Model configuration set.
 */
public static void fromUnEdifactSpec(ZipInputStream specification, ZipOutputStream modelSetOutStream,
        String urn, boolean useShortName) throws IOException {
    try {
        fromSpec(new UnEdifactSpecificationReader(specification, true, useShortName), modelSetOutStream, urn);
    } finally {
        specification.close();
    }
}