Package java.util.zip

Examples of java.util.zip.ZipInputStream


    else {
      earFileName = null;
    }

    WriteStream archiveStream =  null;
    ZipInputStream zipInputStream = null;
    ZipOutputStream zipOutputStream = null;

    try {
      archiveStream = archivePath.openWrite();
      zipOutputStream = new ZipOutputStream(archiveStream);

      zipInputStream = new ZipInputStream(archiveIs);

      ZipEntry zipEntry = zipInputStream.getNextEntry();

      TreeSet<String> entryNames = new TreeSet<String>();

      int copyCount = 0;

      while (zipEntry != null) {
        if (log.isLoggable(Level.FINEST))
          log.log(Level.FINEST, L.l("jsr88 copying entry {0}", zipEntry));

        entryNames.add(zipEntry.getName());

        zipOutputStream.putNextEntry(zipEntry);

        try {
          for (int ch = zipInputStream.read(); ch != -1; ch = zipInputStream.read())
            zipOutputStream.write(ch);
        } catch (IOException e) {
          // XXX: unexpected end of ZLIB input stream.
          log.log(Level.WARNING, L.l("exception copying entry {0}", zipEntry), e);
        }

        zipEntry = zipInputStream.getNextEntry();

        copyCount++;
      }

      if (log.isLoggable(Level.FINER))
        log.log(Level.FINER, L.l("copied {0} entries", copyCount));

      if (archiveIs.read() != -1) {
        if (log.isLoggable(Level.FINE))
          log.log(Level.FINE, L.l("unexpected data at end of archive"));

        while (archiveIs.read() != -1) {}
      }

      int fileCount = 0;

      for (DeploymentPlan.PlanFile file : plan.getFileList()) {
        String zipEntryName = file.getPath();
        if (zipEntryName.startsWith("/"))
          zipEntryName = zipEntryName.substring(1);

        if (log.isLoggable(Level.FINEST))
          log.log(Level.FINEST, L.l("jsr88 plan file {0} output to {1}", file, zipEntryName));

        if (entryNames.contains(zipEntryName))
          log.log(Level.WARNING, L.l("plan file {0} overwrites existing file", zipEntryName));

        entryNames.add(zipEntryName);

        zipEntry = new ZipEntry(zipEntryName);
        zipOutputStream.putNextEntry(zipEntry);
        file.writeToStream(zipOutputStream);

        fileCount++;
      }

      if (log.isLoggable(Level.FINER))
        log.log(Level.FINER, L.l("created {0} entries from plan", fileCount));

      zipInputStream.close();
      zipInputStream = null;

      zipOutputStream.close();
      zipOutputStream = null;

      archiveStream.close();
      archiveStream = null;
    }
    finally {
      if (zipInputStream != null) {
        try {
          zipInputStream.close();
        }
        catch (Exception ex) {
          log.log(Level.FINER, ex.toString(), ex);
        }
      }
View Full Code Here


    private static void loadRARData(JMSProviderData data, PortletRequest request) throws IOException {
        File url = PortletManager.getRepositoryEntry(request, data.getRaURI());
        if(url == null) {
            throw new IOException("Unable to locate entry "+data.getRaURI()+" in repository");
        }
        ZipInputStream in = new ZipInputStream(new FileInputStream(url));
        ZipEntry entry;
        Document doc = null;
        try {
            while((entry = in.getNextEntry()) != null) {
                if(entry.getName().equals("META-INF/ra.xml")) {
                    DocumentBuilderFactory factory = XmlUtil.newDocumentBuilderFactory();
                    factory.setValidating(false);
                    DocumentBuilder builder = factory.newDocumentBuilder();
                    doc = builder.parse(in);
                    in.close();
                    in = null;
                    break;
                } else in.closeEntry();
            }
        } catch (ParserConfigurationException e) {
            log.error("Unable to read META-INF/ra.xml in RAR file '"+data.getRaURI()+"'", e);
        } catch (SAXException e) {
            log.error("Unable to read META-INF/ra.xml in RAR file '"+data.getRaURI()+"'", e);
        } finally {
            if (in != null)
                try {
                    in.close();       
                } catch (IOException ignore) {
                }
        }
        if(doc == null) {
            throw new IOException("Unable to locate META-INF/ra.xml in RAR file '"+data.getRaURI()+"'");
View Full Code Here

    }
   
    private List<String> load(InputStream is) throws IOException {
        List<String> jarContents = new ArrayList<String>();
        try {
            ZipInputStream zis = new ZipInputStream(is);
            ZipEntry ze = zis.getNextEntry();
            while (ze != null) {
                if (ze.isDirectory()) {
                    continue;
                }
                jarContents.add(ze.getName());
                ze = zis.getNextEntry();
            }
        } catch (NullPointerException e) {
            System.out.println("done.");
        }
View Full Code Here

        LOG.debug("Exporting result of {} as {}", reportExec, format);

        // streaming SAX handler from a compressed byte array stream
        ByteArrayInputStream bais = new ByteArrayInputStream(reportExec.getExecResult());
        ZipInputStream zis = new ZipInputStream(bais);
        try {
            // a single ZipEntry in the ZipInputStream (see ReportJob)
            zis.getNextEntry();

            Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
            pipeline.addComponent(new XMLGenerator(zis));

            Map<String, Object> parameters = new HashMap<String, Object>();
View Full Code Here

                        log.trace(_loc.get("scanning-jar-at-url", url));
                    }
                    try {
                        InputStream is = (InputStream) AccessController.doPrivileged(
                                J2DoPrivHelper.openStreamAction(url));
                        scan(new ZipStreamMetaDataIterator(new ZipInputStream(is), newMetaDataFilter()),
                                cparser, names, true, url);
                    } catch (PrivilegedActionException pae) {
                        throw (IOException) pae.getException();
                    }
                } else {
                    if (log.isTraceEnabled()) {
                        log.trace(_loc.get("scanning-url", url));
                    }
                    clss = cparser.parseTypeNames(new URLMetaDataIterator(url));
                    List<String> newNames = Arrays.asList(clss);
                    if (log.isTraceEnabled()) {
                        log.trace(_loc.get("scan-found-names", newNames, url));
                    }
                    names.addAll(newNames);
                    mapPersistentTypeNames(url, clss);
                }
            }
        }
        if (rsrcs != null) {
            String rsrc;
            MetaDataIterator mitr;
            for (Iterator itr = rsrcs.iterator(); itr.hasNext();) {
                rsrc = (String) itr.next();
                if (rsrc.endsWith(".jar")) {
                    url = AccessController.doPrivileged(
                            J2DoPrivHelper.getResourceAction(loader, rsrc));
                    if (url != null) {
                        if (log.isTraceEnabled()) {
                            log.trace(_loc.get("scanning-jar-stream-url", url));
                        }
                        try {
                            InputStream is = (InputStream) AccessController.doPrivileged(
                                    J2DoPrivHelper.openStreamAction(url));
                            scan(new ZipStreamMetaDataIterator(new ZipInputStream(is), newMetaDataFilter()), cparser,
                                    names, true, url);
                        } catch (PrivilegedActionException pae) {
                            throw (IOException) pae.getException();
                        }
                    }
View Full Code Here

        @Override
        public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
            entryMap = new TreeMap<String,ZipTreeNode>();
            final URI uri = URIHelper.retrieveFileURI((IEditorInput) newInput);
            if (uri != null) {
                ZipInputStream zis = null;
                try {
                    zis = new ZipInputStream(uri.toURL().openStream());
                    ZipEntry entry;
                    while ( (entry = zis.getNextEntry()) != null) {
                        ZipTreeNode.addEntry(entryMap, entry);
                    }
                    zis.close();
                }
                catch (IOException e) {
                    Status status = new Status(IStatus.ERROR,
                                               PluginConstants.PLUGIN_ID,
                                               0,
                                               "I/O error reading JAR file contents",
                                               e);
                    ErrorDialog.openError(managedForm.getForm().getShell(), "Error", null, status);
                }
                finally {
                    if (zis != null) {
                        try {
                            zis.close();
                        }
                        catch (IOException e) {
                            // nothing to do
                        }
                    }
View Full Code Here

        // @todo make this work with unpacked
        entries = new ArrayList();
        InputStream is = null;
        try {
            is = moduleURL.openStream();
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                entries.add(entry.getName());
            }
        } catch (IOException e) {
            throw (DDBeanCreateException) new DDBeanCreateException("Unable to create list of entries").initCause(e);
        } finally {
View Full Code Here

            fis.close();
        }
    }

    public static void unpack(File to, InputStream from) throws IOException {
        ZipInputStream zis = new ZipInputStream(from);
        try {
            ZipEntry entry;
            byte[] buffer = new byte[4096];
            while ((entry = zis.getNextEntry()) != null) {
                File out = new File(to, entry.getName());
                if (entry.isDirectory()) {
                    out.mkdirs();
                } else {
                    if (!entry.getName().equals("META-INF/startup-jar")) {
                        out.getParentFile().mkdirs();
                        OutputStream os = new FileOutputStream(out);
                        try {
                            int count;
                            while ((count = zis.read(buffer)) > 0) {
                                os.write(buffer, 0, count);
                            }
                        } finally {
                            os.close();
                        }
                        zis.closeEntry();
                    }
                }
            }
        } catch (IOException e) {
            delete(to);
View Full Code Here

    private void assertWrittenFile(File f, List<LogFileDetails> details) throws FileNotFoundException, IOException
    {
        FileInputStream fis = new FileInputStream(f);
        try
        {
            ZipInputStream zis = new ZipInputStream(fis);
            ZipEntry ze = zis.getNextEntry();

            while (ze != null)
            {
                String entryName = ze.getName();
                String[] parts = entryName.split("/");

                String appenderName = parts[0];
                String logFileName = parts[1];

                LogFileDetails d = findLogFileDetails(logFileName, appenderName, details);

                assertNotNull("Unexpected entry " + entryName, d);
                details.remove(d);

                File logFile = d.getLocation();
                String logContent = FileUtils.readFileAsString(logFile);

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                int len;
                while ((len = zis.read(buffer)) > 0)
                {
                    baos.write(buffer, 0, len);
                }
                baos.close();

                assertEquals("Unexpected log file content", logContent, baos.toString());

                ze = zis.getNextEntry();
            }

            zis.closeEntry();
            zis.close();

        }
        finally
        {
            if (fis != null)
View Full Code Here

   */
  public void parse(InputStream ins, ContentCreator creator)
      throws IOException, RepositoryException {
        try {
            creator.createNode(null, NT_FOLDER, null);
            final ZipInputStream zis = new ZipInputStream(ins);
            ZipEntry entry;
            do {
                entry = zis.getNextEntry();
                if ( entry != null ) {
                    if ( !entry.isDirectory() ) {
                        String name = entry.getName();
                        int pos = name.lastIndexOf('/');
                        if ( pos != -1 ) {
                            creator.switchCurrentNode(name.substring(0, pos), NT_FOLDER);
                        }
                        creator.createFileAndResourceNode(name, new CloseShieldInputStream(zis), null, entry.getTime());
                        creator.finishNode();
                        creator.finishNode();
                        if ( pos != -1 ) {
                            creator.finishNode();
                        }
                    }
                    zis.closeEntry();
                }

            } while ( entry != null );
            creator.finishNode();
        } finally {
View Full Code Here

TOP

Related Classes of java.util.zip.ZipInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.