Example usage for java.util.zip ZipInputStream ZipInputStream

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

Introduction

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

Prototype

public ZipInputStream(InputStream in) 

Source Link

Document

Creates a new ZIP input stream.

Usage

From source file:com.thoughtworks.go.util.ZipUtilTest.java

@Test
void shouldReadContentFromFileInsideZip() throws IOException, URISyntaxException {
    String contents = zipUtil.getFileContentInsideZip(
            new ZipInputStream(
                    new FileInputStream(new File(getClass().getResource("/dummy-plugins.zip").toURI()))),
            "version.txt");
    assertThat(contents).isEqualTo("13.3.0(17222-4c7fabcb9c9e9c)");
}

From source file:es.juntadeandalucia.panelGestion.negocio.utiles.Utils.java

public static InputStream getShapefileFromCompressed(InputStream is, ShpFileType type) {
    InputStream shapefile = null;
    ZipInputStream zis = new ZipInputStream(is);
    ZipEntry ze;/*  ww  w  .ja v a  2s.  c  o m*/
    try {
        while ((ze = zis.getNextEntry()) != null) {
            if (!ze.isDirectory()) {
                String fileName = ze.getName().toLowerCase();
                String baseShapefileName = type.toBase(fileName);
                if (baseShapefileName != null) {
                    shapefile = zis;
                    break;
                }
            }
        }
    } catch (IOException e) {
        try {
            zis.closeEntry();
        } catch (IOException e2) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            zis.close();
        } catch (IOException e2) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return shapefile;
}

From source file:com.dangdang.config.service.web.mb.PropertyGroupManagedBean.java

/**
 * ?//from  w w  w  . jav  a2s .  c om
 * 
 * @param event
 */
public void propertyZipUpload(FileUploadEvent event) {
    String fileName = event.getFile().getFileName();
    LOGGER.info("Deal uploaded file: {}", fileName);
    ZipInputStream zipInputStream = null;
    try {
        zipInputStream = new ZipInputStream(event.getFile().getInputstream());
        ZipEntry nextEntry = null;
        while ((nextEntry = zipInputStream.getNextEntry()) != null) {
            String entryName = nextEntry.getName();
            savePropertyGroup(entryName, Files.getNameWithoutExtension(entryName), zipInputStream);
        }
    } catch (IOException e) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "Upload File error.", fileName));
        LOGGER.error("Upload File Exception.", e);
    } finally {
        if (zipInputStream != null) {
            try {
                zipInputStream.close();
            } catch (IOException e) {
                // DO NOTHING
            }
        }
    }
}

From source file:com.t3.persistence.FileUtil.java

public static void unzip(URL url, File destDir) throws IOException {
    if (url == null)
        throw new IOException("URL cannot be null");

    try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(url.openStream()))) {
        unzip(zis, destDir);/*from w w w. j a v a 2s  .c  o m*/
    }
}

From source file:ee.ria.xroad.common.messagelog.archive.LogArchiveCacheTest.java

private void assertZip(List<String> expectedEntryNames, byte[] archiveBytes) throws IOException {
    if (archiveBytes == null || archiveBytes.length == 0) {
        fail("Bytes of zip archive must not be empty");
    }/* w  w w. j  a  va  2s .  c o m*/

    InputStream archiveBytesInput = new ByteArrayInputStream(archiveBytes);

    try (ZipInputStream zip = new ZipInputStream(archiveBytesInput)) {
        for (int i = 0; i < expectedEntryNames.size(); i++) {
            ZipEntry entry = zip.getNextEntry();

            assertNotNull(getZipEntryNotPresentMessage(i), entry);
            assertThat(entry.getName(), isIn(expectedEntryNames));
        }

        ZipEntry linkingInfoEntry = zip.getNextEntry();

        if (linkingInfoEntry == null) {
            throw new RuntimeException("There is no linking info present in the archive!");
        }

        assertEquals("linkinginfo", linkingInfoEntry.getName());

        assertNull("Zip entries must be taken by this point.", zip.getNextEntry());
    }
}