Example usage for java.util.zip ZipInputStream available

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

Introduction

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

Prototype

public int available() throws IOException 

Source Link

Document

Returns 0 after EOF has reached for the current entry data, otherwise always return 1.

Usage

From source file:InstallJars.java

public void installJar(URLConnection conn, String target, boolean doExpand, boolean doRun) throws IOException {
    if (doExpand) {
        println("Expanding JAR file " + target + " from " + conn.getURL().toExternalForm());
        // *** may need to specialize for JAR format ***
        ZipInputStream zis = new ZipInputStream(
                new BufferedInputStream(conn.getInputStream(), BLOCK_SIZE * BLOCK_COUNT));
        int count = 0;
        prepDirs(target, true);/*from   w w  w  .j a  v a 2 s  .  c  o  m*/
        try {
            while (zis.available() > 0) {
                ZipEntry ze = zis.getNextEntry();
                copyEntry(target, zis, ze);
                count++;
            }
        } finally {
            try {
                zis.close();
            } catch (IOException ioe) {
            }
        }
        println("Installed " + count + " files/directories");
    } else {
        print("Installing JAR file " + target + " from " + conn.getURL().toExternalForm());
        copyStream(conn, target);
        println();
        if (doRun) {
            runTarget(target, true);
        }
    }
}

From source file:org.tonguetied.datatransfer.ExportServiceTest.java

public final void testCreateArchiveWithFiles() throws Exception {
    archiveTestDirectory = new File(USER_DIR, "testCreateArchiveWithFiles");
    FileUtils.forceMkdir(archiveTestDirectory);
    FileUtils.writeStringToFile(new File(archiveTestDirectory, "temp"), "test.value=value");
    FileUtils.writeStringToFile(new File(archiveTestDirectory, "temp_en"), "test.value=valyoo");
    assertEquals(2, archiveTestDirectory.listFiles().length);
    assertTrue(archiveTestDirectory.isDirectory());
    dataService.createArchive(archiveTestDirectory);
    assertEquals(3, archiveTestDirectory.listFiles().length);
    // examine zip file
    File[] files = archiveTestDirectory.listFiles(new FileExtensionFilter(".zip"));
    assertEquals(1, files.length);//w  w  w .ja v a 2  s. co  m
    ZipInputStream zis = null;
    final String[] fileNames = { "temp", "temp_en" };
    try {
        zis = new ZipInputStream(new FileInputStream(files[0]));
        ZipEntry zipEntry = zis.getNextEntry();
        Arrays.binarySearch(fileNames, zipEntry.getName());
        zis.closeEntry();
        zipEntry = zis.getNextEntry();
        Arrays.binarySearch(fileNames, zipEntry.getName());
        zis.closeEntry();

        // confirm that there are no more files in the archive
        assertEquals(0, zis.available());
    } finally {
        IOUtils.closeQuietly(zis);
    }
}

From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java

/**
 * @param file/*from  ww  w .  j  ava  2 s.  com*/
 * @return name of report resource contained in file, or null if file does not
 * contain a report resource.
 */
protected String getSpReportResourceName(final File file) {
    try {
        ZipInputStream zin = new ZipInputStream(new FileInputStream(file));
        ZipEntry app = zin.getNextEntry();
        if (app == null) {
            return null;
        }
        if (zin.available() == 0) {
            return null;
        }
        String appStr = readZipEntryToString(zin, app);
        if (isSpReportResource(appStr)) {
            Element appElement = XMLHelper.readStrToDOM4J(appStr);
            return XMLHelper.getAttr(appElement, "name", null);
        }
        return null;
    } catch (ZipException ex) {
        //I think this means it is not a zip file.
        return null;
    } catch (Exception ex) {
        ex.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ResourceImportExportDlg.class, ex);
        return null;
    }
}

From source file:com.cloudera.whirr.cm.server.impl.CmServerImpl.java

@Override
@CmServerCommandMethod(name = "client")
public boolean getServiceConfigs(final CmServerCluster cluster, final File directory) throws CmServerException {

    final AtomicBoolean executed = new AtomicBoolean(false);
    try {/*  ww  w  .j  a va  2s.co  m*/

        if (isProvisioned(cluster)) {
            logger.logOperation("GetConfig", new CmServerLogSyncCommand() {
                @Override
                public void execute() throws IOException {
                    for (ApiService apiService : apiResourceRootV3.getClustersResource()
                            .getServicesResource(getName(cluster)).readServices(DataView.SUMMARY)) {
                        CmServerServiceType type = CmServerServiceType.valueOfId(apiService.getType());
                        if (type.equals(CmServerServiceType.HDFS) || type.equals(CmServerServiceType.MAPREDUCE)
                                || type.equals(CmServerServiceType.YARN)
                                || type.equals(CmServerServiceType.HBASE)
                                || versionApi >= 4 && type.equals(CmServerServiceType.HIVE)
                                || versionApi >= 5 && type.equals(CmServerServiceType.SOLR)) {
                            ZipInputStream configInputZip = null;
                            try {
                                InputStreamDataSource configInput = apiResourceRootV3.getClustersResource()
                                        .getServicesResource(getName(cluster))
                                        .getClientConfig(apiService.getName());
                                if (configInput != null) {
                                    configInputZip = new ZipInputStream(configInput.getInputStream());
                                    ZipEntry configInputZipEntry = null;
                                    while ((configInputZipEntry = configInputZip.getNextEntry()) != null) {
                                        String configFile = configInputZipEntry.getName();
                                        if (configFile.contains(File.separator)) {
                                            configFile = configFile.substring(
                                                    configFile.lastIndexOf(File.separator),
                                                    configFile.length());
                                        }
                                        directory.mkdirs();
                                        BufferedWriter configOutput = null;
                                        try {
                                            int read;
                                            configOutput = new BufferedWriter(
                                                    new FileWriter(new File(directory, configFile)));
                                            while (configInputZip.available() > 0) {
                                                if ((read = configInputZip.read()) != -1) {
                                                    configOutput.write(read);
                                                }
                                            }
                                        } finally {
                                            configOutput.close();
                                        }
                                    }
                                }
                            } finally {
                                if (configInputZip != null) {
                                    configInputZip.close();
                                }
                            }
                            executed.set(true);
                        }
                    }
                }
            });
        }

    } catch (Exception e) {
        throw new CmServerException("Failed to get cluster config", e);
    }

    return executed.get();

}

From source file:nova.core.render.model.TechneModelProvider.java

@Override
public void load(InputStream stream) {
    try {// w w w.j a  v a2 s . com
        Map<String, byte[]> zipContents = new HashMap<>();
        ZipInputStream zipInput = new ZipInputStream(stream);
        ZipEntry entry;
        while ((entry = zipInput.getNextEntry()) != null) {
            byte[] data = new byte[(int) entry.getSize()];
            // For some reason, using read(byte[]) makes reading stall upon reaching a 0x1E byte
            int i = 0;
            while (zipInput.available() > 0 && i < data.length) {
                data[i++] = (byte) zipInput.read();
            }
            zipContents.put(entry.getName(), data);
        }

        byte[] modelXml = zipContents.get("model.xml");
        if (modelXml == null) {
            throw new RenderException("Model " + name + " contains no model.xml file");
        }

        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse(new ByteArrayInputStream(modelXml));

        NodeList nodeListTechne = document.getElementsByTagName("Techne");
        if (nodeListTechne.getLength() < 1) {
            throw new RenderException("Model " + name + " contains no Techne tag");
        }

        NodeList nodeListModel = document.getElementsByTagName("Model");
        if (nodeListModel.getLength() < 1) {
            throw new RenderException("Model " + name + " contains no Model tag");
        }

        NamedNodeMap modelAttributes = nodeListModel.item(0).getAttributes();
        if (modelAttributes == null) {
            throw new RenderException("Model " + name + " contains a Model tag with no attributes");
        }

        NodeList textureSize = document.getElementsByTagName("TextureSize");
        if (textureSize.getLength() == 0)
            throw new RenderException("Model has no texture size");

        String[] textureDimensions = textureSize.item(0).getTextContent().split(",");
        double textureWidth = Integer.parseInt(textureDimensions[0]);
        double textureHeight = Integer.parseInt(textureDimensions[1]);

        NodeList shapes = document.getElementsByTagName("Shape");

        for (int i = 0; i < shapes.getLength(); i++) {
            Node shape = shapes.item(i);
            NamedNodeMap shapeAttributes = shape.getAttributes();
            if (shapeAttributes == null) {
                throw new RenderException("Shape #" + (i + 1) + " in " + name + " has no attributes");
            }

            Node name = shapeAttributes.getNamedItem("name");
            String shapeName = null;
            if (name != null) {
                shapeName = name.getNodeValue();
            }
            if (shapeName == null) {
                shapeName = "Shape #" + (i + 1);
            }

            String shapeType = null;
            Node type = shapeAttributes.getNamedItem("type");
            if (type != null) {
                shapeType = type.getNodeValue();
            }

            if (shapeType != null && !cubeIDs.contains(shapeType)) {
                System.out.println(
                        "Model shape [" + shapeName + "] in " + this.name + " is not a cube, ignoring");
                continue;
            }

            boolean mirrored = false;
            String[] offset = new String[3];
            String[] position = new String[3];
            String[] rotation = new String[3];
            String[] size = new String[3];
            String[] textureOffset = new String[2];

            NodeList shapeChildren = shape.getChildNodes();
            for (int j = 0; j < shapeChildren.getLength(); j++) {
                Node shapeChild = shapeChildren.item(j);

                String shapeChildName = shapeChild.getNodeName();
                String shapeChildValue = shapeChild.getTextContent();
                if (shapeChildValue != null) {
                    shapeChildValue = shapeChildValue.trim();

                    switch (shapeChildName) {
                    case "IsMirrored":
                        mirrored = !shapeChildValue.equals("False");
                        break;
                    case "Offset":
                        offset = shapeChildValue.split(",");
                        break;
                    case "Position":
                        position = shapeChildValue.split(",");
                        break;
                    case "Rotation":
                        rotation = shapeChildValue.split(",");
                        break;
                    case "Size":
                        size = shapeChildValue.split(",");
                        break;
                    case "TextureOffset":
                        textureOffset = shapeChildValue.split(",");
                        break;
                    }
                }
            }

            /*
                 Generate new models
                 Models in Techne are based on cubes.
                 Each cube is, by default, skewed to the side. They are not centered.
                    
                 Everything is scaled by a factor of 16.
                 The y coordinate is inversed, y = 24 is the surface
                 The z coordinate is inverted, too.
             */
            double positionX = Double.parseDouble(position[0]) / 16d;
            double positionY = (16 - Double.parseDouble(position[1])) / 16d;
            double positionZ = -Double.parseDouble(position[2]) / 16d;

            double sizeX = Double.parseDouble(size[0]) / 16d;
            double sizeY = Double.parseDouble(size[1]) / 16d;
            double sizeZ = Double.parseDouble(size[2]) / 16d;

            double offsetX = Double.parseDouble(offset[0]) / 16d;
            double offsetY = -Double.parseDouble(offset[1]) / 16d;
            double offsetZ = -Double.parseDouble(offset[2]) / 16d;

            double angleX = -Math.toRadians(Double.parseDouble(rotation[0]));
            double angleY = Math.toRadians(Double.parseDouble(rotation[1]));
            double angleZ = Math.toRadians(Double.parseDouble(rotation[2]));

            double textureOffsetU = Double.parseDouble(textureOffset[0]);
            double textureOffsetV = Double.parseDouble(textureOffset[1]);

            CubeTextureCoordinates textureCoordinates = new TechneCubeTextureCoordinates(textureWidth,
                    textureHeight, textureOffsetU, textureOffsetV, sizeX, sizeY, sizeZ);

            final String modelName = shapeName;
            MeshModel modelPart = new MeshModel(modelName);
            BlockRenderPipeline.drawCube(modelPart, offsetX, offsetY - sizeY, offsetZ - sizeZ, offsetX + sizeX,
                    offsetY, offsetZ, textureCoordinates);

            MatrixStack ms = new MatrixStack();
            ms.translate(positionX, positionY, positionZ);
            ms.rotate(Vector3D.PLUS_J, angleY);
            ms.rotate(Vector3D.PLUS_I, angleX);
            ms.rotate(Vector3D.PLUS_K, angleZ);
            modelPart.matrix = ms;
            modelPart.textureOffset = new Vector2D(Integer.parseInt(textureOffset[0]),
                    Integer.parseInt(textureOffset[1]));

            if (model.children.stream().anyMatch(m -> m.name.equals(modelName))) {
                throw new RenderException(
                        "Model contained duplicate part name: '" + shapeName + "' node #" + i);
            }

            model.children.add(modelPart);
        }
    } catch (ZipException e) {
        throw new RenderException("Model " + name + " is not a valid zip file");
    } catch (IOException e) {
        throw new RenderException("Model " + name + " could not be read", e);
    } catch (SAXException e) {
        throw new RenderException("Model " + name + " contains invalid XML", e);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.apache.kylin.common.util.ZipFileUtils.java

public static void decompressZipfileToDirectory(String zipFileName, File outputFolder) throws IOException {
    ZipInputStream zipInputStream = null;
    try {//from w w w  .  j  a va 2  s  .co m
        zipInputStream = new ZipInputStream(new FileInputStream(zipFileName));
        ZipEntry zipEntry = null;
        while ((zipEntry = zipInputStream.getNextEntry()) != null) {
            logger.info("decompressing " + zipEntry.getName() + " is directory:" + zipEntry.isDirectory()
                    + " available: " + zipInputStream.available());

            File temp = new File(outputFolder, zipEntry.getName());
            if (zipEntry.isDirectory()) {
                temp.mkdirs();
            } else {
                temp.getParentFile().mkdirs();
                temp.createNewFile();
                temp.setLastModified(zipEntry.getTime());
                FileOutputStream outputStream = new FileOutputStream(temp);
                try {
                    IOUtils.copy(zipInputStream, outputStream);
                } finally {
                    IOUtils.closeQuietly(outputStream);
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(zipInputStream);
    }
}

From source file:org.ejbca.ui.web.admin.certprof.CertProfilesBean.java

public void importProfilesFromZip(byte[] filebuffer) throws CertificateProfileExistsException,
        AuthorizationDeniedException, NumberFormatException, IOException {

    if (filebuffer.length == 0) {
        throw new IllegalArgumentException("No input file");
    }/*from  ww  w .  ja  v  a 2 s .  c  o  m*/

    String importedFiles = "";
    String ignoredFiles = "";
    int nrOfFiles = 0;

    ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(filebuffer));
    ZipEntry ze = zis.getNextEntry();
    if (ze == null) {
        String msg = uploadFile.getName() + " is not a zip file.";
        log.info(msg);
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
        return;
    }

    do {
        nrOfFiles++;
        String filename = ze.getName();
        if (log.isDebugEnabled()) {
            log.debug("Importing file: " + filename);
        }

        if (ignoreFile(filename)) {
            ignoredFiles += filename + ", ";
            continue;
        }

        try {
            filename = URLDecoder.decode(filename, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("UTF-8 was not a known character encoding", e);
        }
        int index1 = filename.indexOf("_");
        int index2 = filename.lastIndexOf("-");
        int index3 = filename.lastIndexOf(".xml");
        String profilename = filename.substring(index1 + 1, index2);
        int profileid = 0;
        try {
            profileid = Integer.parseInt(filename.substring(index2 + 1, index3));
        } catch (NumberFormatException e) {
            if (log.isDebugEnabled()) {
                log.debug("NumberFormatException parsing certificate profile id: " + e.getMessage());
            }
            ignoredFiles += filename + ", ";
            continue;
        }
        if (log.isDebugEnabled()) {
            log.debug("Extracted profile name '" + profilename + "' and profile ID '" + profileid + "'");
        }

        if (ignoreProfile(filename, profilename, profileid)) {
            ignoredFiles += filename + ", ";
            continue;
        }

        if (getEjbcaWebBean().getEjb().getCertificateProfileSession()
                .getCertificateProfile(profileid) != null) {
            log.warn("Certificate profile id '" + profileid
                    + "' already exist in database. Adding with a new profile id instead.");
            profileid = -1; // means we should create a new id when adding the cert profile
        }

        byte[] filebytes = new byte[102400];
        int i = 0;
        while ((zis.available() == 1) && (i < filebytes.length)) {
            filebytes[i++] = (byte) zis.read();
        }

        final CertificateProfile certificateProfile = getCertProfileFromByteArray(profilename, filebytes);
        if (certificateProfile == null) {
            String msg = "Faulty XML file '" + filename + "'. Failed to read Certificate Profile.";
            log.info(msg + " Ignoring file.");
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
            continue;
        }

        certificateProfile.setAvailableCAs(getEjbcaWebBean().getInformationMemory().getAuthorizedCAIds());
        getEjbcaWebBean().getEjb().getCertificateProfileSession().addCertificateProfile(getAdmin(), profilename,
                certificateProfile);
        getEjbcaWebBean().getInformationMemory().certificateProfilesEdited();
        importedFiles += filename + ", ";
        log.info("Added Certificate profile: " + profilename);
    } while ((ze = zis.getNextEntry()) != null);
    zis.closeEntry();
    zis.close();

    String msg = uploadFile.getName() + " contained " + nrOfFiles + " files. ";
    log.info(msg);
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, msg, null));

    if (StringUtils.isNotEmpty(importedFiles)) {
        importedFiles = importedFiles.substring(0, importedFiles.length() - 2);
    }
    msg = "Imported Certificate Profiles from files: " + importedFiles;
    if (log.isDebugEnabled()) {
        log.debug(msg);
    }
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, msg, null));

    if (StringUtils.isNotEmpty(ignoredFiles)) {
        ignoredFiles = ignoredFiles.substring(0, ignoredFiles.length() - 2);
    }
    msg = "Ignored files: " + ignoredFiles;
    if (log.isDebugEnabled()) {
        log.debug(msg);
    }
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, msg, null));
}

From source file:org.ejbca.ui.web.admin.rainterface.RAInterfaceBean.java

public String importProfilesFromZip(byte[] filebuffer) {
    if (log.isTraceEnabled()) {
        log.trace(">importProfiles(): " + importedProfileName + " - " + filebuffer.length + " bytes");
    }/*from  w w w  . j a v a 2s . c om*/

    String retmsg = "";
    String faultXMLmsg = "";

    if (StringUtils.isEmpty(importedProfileName) || filebuffer.length == 0) {
        retmsg = "Error: No input file";
        log.error(retmsg);
        return retmsg;
    }

    int importedFiles = 0;
    int ignoredFiles = 0;
    int nrOfFiles = 0;
    try {
        ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(filebuffer));
        ZipEntry ze = zis.getNextEntry();
        if (ze == null) {
            retmsg = "Error: Expected a zip file. '" + importedProfileName + "' is not a  zip file.";
            log.error(retmsg);
            return retmsg;
        }

        do {
            nrOfFiles++;
            String filename = ze.getName();
            if (log.isDebugEnabled()) {
                log.debug("Importing file: " + filename);
            }

            if (ignoreFile(filename)) {
                ignoredFiles++;
                continue;
            }

            String profilename;
            filename = URLDecoder.decode(filename, "UTF-8");

            int index1 = filename.indexOf("_");
            int index2 = filename.lastIndexOf("-");
            int index3 = filename.lastIndexOf(".xml");
            profilename = filename.substring(index1 + 1, index2);
            int profileid = 0;
            try {
                profileid = Integer.parseInt(filename.substring(index2 + 1, index3));
            } catch (NumberFormatException e) {
                if (log.isDebugEnabled()) {
                    log.debug("NumberFormatException parsing certificate profile id: " + e.getMessage());
                }
                ignoredFiles++;
                continue;
            }
            if (log.isDebugEnabled()) {
                log.debug("Extracted profile name '" + profilename + "' and profile ID '" + profileid + "'");
            }

            if (ignoreProfile(filename, profilename, profileid)) {
                ignoredFiles++;
                continue;
            }

            if (endEntityProfileSession.getEndEntityProfile(profileid) != null) {
                int newprofileid = endEntityProfileSession.findFreeEndEntityProfileId();
                log.warn("Entity profileid '" + profileid + "' already exist in database. Using " + newprofileid
                        + " instead.");
                profileid = newprofileid;
            }

            byte[] filebytes = new byte[102400];
            int i = 0;
            while ((zis.available() == 1) && (i < filebytes.length)) {
                filebytes[i++] = (byte) zis.read();
            }

            EndEntityProfile eprofile = getEEProfileFromByteArray(profilename, filebytes);
            if (eprofile == null) {
                String msg = "Faulty XML file '" + filename + "'. Failed to read End Entity Profile.";
                log.info(msg + " Ignoring file.");
                ignoredFiles++;
                faultXMLmsg += filename + ", ";
                continue;
            }

            profiles.addEndEntityProfile(profilename, eprofile);
            importedFiles++;
            log.info("Added EndEntity profile: " + profilename);

        } while ((ze = zis.getNextEntry()) != null);
        zis.closeEntry();
        zis.close();
    } catch (UnsupportedEncodingException e) {
        retmsg = "Error: UTF-8 was not a known character encoding.";
        log.error(retmsg, e);
        return retmsg;
    } catch (IOException e) {
        log.error(e);
        retmsg = "Error: " + e.getLocalizedMessage();
        return retmsg;
    } catch (AuthorizationDeniedException e) {
        log.error(e);
        retmsg = "Error: " + e.getLocalizedMessage();
        return retmsg;
    } catch (EndEntityProfileExistsException e) {
        log.error(e);
        retmsg = "Error: " + e.getLocalizedMessage();
        return retmsg;
    }

    if (StringUtils.isNotEmpty(faultXMLmsg)) {
        faultXMLmsg = faultXMLmsg.substring(0, faultXMLmsg.length() - 2);
        retmsg = "Faulty XML files: " + faultXMLmsg + ". " + importedFiles + " profiles were imported.";
    } else {
        retmsg = importedProfileName + " contained " + nrOfFiles + " files. " + importedFiles
                + " EndEntity Profiles were imported and " + ignoredFiles + " files  were ignored.";
    }
    log.info(retmsg);

    return retmsg;
}

From source file:org.gradle.api.plugins.buildcomparison.outcome.internal.archive.entry.FileToArchiveEntrySetTransformer.java

private ImmutableSet<ArchiveEntry> walk(InputStream archiveInputStream,
        ImmutableSet.Builder<ArchiveEntry> allEntries, ImmutableList<String> parentPaths) {
    ImmutableSet.Builder<ArchiveEntry> entries = ImmutableSet.builder();
    ZipInputStream zipStream = new ZipInputStream(archiveInputStream);

    try {/*from w  w  w  .  j a va 2s .  c  o  m*/
        ZipEntry entry = zipStream.getNextEntry();
        while (entry != null) {
            ArchiveEntry.Builder builder = new ArchiveEntry.Builder();
            builder.setParentPaths(parentPaths);
            builder.setPath(entry.getName());
            builder.setCrc(entry.getCrc());
            builder.setDirectory(entry.isDirectory());
            builder.setSize(entry.getSize());
            if (!builder.isDirectory() && (zipStream.available() == 1)) {
                boolean zipEntry;
                final BufferedInputStream bis = new BufferedInputStream(zipStream) {
                    @Override
                    public void close() throws IOException {
                    }
                };
                bis.mark(Integer.MAX_VALUE);
                zipEntry = new ZipInputStream(bis).getNextEntry() != null;
                bis.reset();
                if (zipEntry) {
                    ImmutableList<String> nextParentPaths = ImmutableList.<String>builder().addAll(parentPaths)
                            .add(entry.getName()).build();
                    ImmutableSet<ArchiveEntry> subEntries = walk(bis, allEntries, nextParentPaths);
                    builder.setSubEntries(subEntries);
                }
            }

            ArchiveEntry archiveEntry = builder.build();
            entries.add(archiveEntry);
            allEntries.add(archiveEntry);
            zipStream.closeEntry();
            entry = zipStream.getNextEntry();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        IOUtils.closeQuietly(zipStream);
    }

    return entries.build();
}

From source file:org.jetbrains.jet.jvm.compiler.longTest.ResolveDescriptorsFromExternalLibraries.java

private boolean testLibraryFile(@Nullable File jar, @NotNull String libDescription, int classesPerChunk)
        throws IOException {
    System.out.println("Testing library " + libDescription + "...");
    if (jar != null) {
        System.out.println("Using file " + jar);
    } else {//from w  ww  . j a  v a2s .  c  o  m
        jar = PathUtil.findRtJar();
        System.out.println("Using rt.jar: " + jar);
    }

    long start = System.currentTimeMillis();

    FileInputStream is = new FileInputStream(jar);
    boolean hasErrors = false;
    try {
        ZipInputStream zip = new ZipInputStream(is);

        while (zip.available() > 0) {
            hasErrors |= parseLibraryFileChunk(jar, libDescription, zip, classesPerChunk);
        }
    } finally {
        try {
            is.close();
        } catch (Throwable e) {
        }
    }

    System.out.println("Testing library " + libDescription + " done in "
            + TimeUtils.millisecondsToSecondsString(System.currentTimeMillis() - start) + "s "
            + (hasErrors ? "with" : "without") + " errors");

    return hasErrors;
}