Package java.util.zip

Examples of java.util.zip.ZipInputStream


                root.delete();
            }
        }

        private void unpack(File source, File target) throws IOException {
            ZipInputStream input = null;
            try {
                input = new ZipInputStream(new FileInputStream(source));
                for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
                    if (entry.isDirectory()) {
                        (new File(target, entry.getName())).mkdirs();
                    }
                    else {
                        OutputStream output = null;
                        try {
                            output = new FileOutputStream(target);
                            byte[] buffer = new byte[4096];
                            for (int i = input.read(buffer); i > -1; i = input.read(buffer)) {
                                output.write(buffer, 0, i);
                            }
                        }
                        finally {
                            closeSilently(output);
                        }
                    }
                    input.closeEntry();
                }
            }
            finally {
                closeSilently(input);
            }
View Full Code Here


        final InputStream ins = rsrc.getInputStream();

        Manifest result = null;

        if ( ins != null ) {
            ZipInputStream jis = null;
            try {
                jis = new ZipInputStream(ins);

                ZipEntry entry;

                while ( (entry = jis.getNextEntry()) != null ) {
                    if (entry.getName().equals("OSGI-INF/SUBSYSTEM.MF") ) {
                        result = new Manifest(jis);
                    }
                }

            } finally {

                // close the jar stream or the input stream, if the jar
                // stream is set, we don't need to close the input stream
                // since closing the jar stream closes the input stream
                if (jis != null) {
                    try {
                        jis.close();
                    } catch (IOException ignore) {
                    }
                } else {
                    try {
                        ins.close();
View Full Code Here

        try
        {
            if (url.getPath().endsWith(".zip"))
            {
                ZipInputStream zin = new ZipInputStream(FileUtil.openURL(url));
                ZipEntry entry = zin.getNextEntry();
                while (entry != null)
                {
                    if (entry.getName().equals("repository.xml"))
                    {
                        is = zin;
                        break;
                    }
                    entry = zin.getNextEntry();
                }
            }
            else
            {
                is = FileUtil.openURL(url);
View Full Code Here

            private byte[] loadEntry(String name) throws IOException
            {
                InputStream is = FileUtil.openURL(bundleUrl);
                try
                {
                    ZipInputStream jis = new ZipInputStream(is);
                    for (ZipEntry e = jis.getNextEntry(); e != null; e = jis.getNextEntry())
                    {
                        if (name.equalsIgnoreCase(e.getName()))
                        {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            byte[] buf = new byte[1024];
                            int n;
                            while ((n = jis.read(buf, 0, buf.length)) > 0)
                            {
                                baos.write(buf, 0, n);
                            }
                            return baos.toByteArray();
                        }
View Full Code Here

                InputStream ins = null;
                try
                {
                    ins = url.openStream();
                    ZipInputStream zin = new ZipInputStream( ins );
                    for ( ZipEntry zentry = zin.getNextEntry(); zentry != null; zentry = zin.getNextEntry() )
                    {
                        String name = zentry.getName();

                        // ignore directory entries
                        if ( name.endsWith( "/" ) )
View Full Code Here

            // license is in a nested JAR
            final URL zipResource = bundle.getResource( pathInfo.innerJar );
            if ( zipResource != null )
            {
                final InputStream input = zipResource.openStream();
                ZipInputStream zin = null;
                try
                {
                    zin = new ZipInputStream( input );
                    for ( ZipEntry zentry = zin.getNextEntry(); zentry != null; zentry = zin.getNextEntry() )
                    {
                        if ( pathInfo.licenseFile.equals( zentry.getName() ) )
                        {
                            IOUtils.copy( zin, response.getWriter() );
                            return true;
View Full Code Here

        workspace.unzipFrom(firstZip.openStream());
        listener.getLogger().println("Staging second zip: " + secondZip);
        workspace.unzipFrom(secondZip.openStream());

        // Get list of files changed in secondZip.
        ZipInputStream zip = new ZipInputStream(secondZip.openStream());
        ZipEntry e;
        ExtractChangeLogParser.ExtractChangeLogEntry changeLog = new ExtractChangeLogParser.ExtractChangeLogEntry(secondZip.toString());

        try {
            while ((e = zip.getNextEntry()) != null) {
                if (!e.isDirectory())
                    changeLog.addFile(new ExtractChangeLogParser.FileInZip(e.getName()));
            }
        }
        finally {
            zip.close();
        }
        saveToChangeLog(changeLogFile, changeLog);

        return true;
    }
View Full Code Here

    }
  }

  private void unZipFile(final String zipFilePath,
      final String destinationPath) throws IOException {
    ZipInputStream zis = null;
    try {

      zis = new ZipInputStream(new FileInputStream(zipFilePath));
      ZipEntry entry;

      while ((entry = zis.getNextEntry()) != null) {

        // Create a file on HDD in the destinationPath directory
        // destinationPath is a "root" folder, where you want to extract
        // your ZIP file
        final File entryFile = new File(destinationPath,
View Full Code Here

    }

    private void unzip(InputStream inputStream, File destination, boolean overwrite) {
        try {
            byte[] buf = new byte[1024];
            ZipInputStream zipinputstream = null;
            ZipEntry zipentry;
            zipinputstream = new ZipInputStream(inputStream);

            zipentry = zipinputstream.getNextEntry();
            while (zipentry != null) {
                int n;
                FileOutputStream fileoutputstream;
                File newFile = new File(destination, zipentry.getName());
                if (zipentry.isDirectory()) {
                    newFile.mkdirs();
                    zipentry = zipinputstream.getNextEntry();
                    continue;
                }

                if (newFile.exists() && overwrite) {
                    log.info("Overwriting " + newFile);
                    newFile.delete();
                }

                fileoutputstream = new FileOutputStream(newFile);

                while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
                    fileoutputstream.write(buf, 0, n);
                }

                fileoutputstream.close();
                zipinputstream.closeEntry();
                zipentry = zipinputstream.getNextEntry();

            }

            zipinputstream.close();
        } catch (Exception e) {
            throw new IllegalStateException("Can't unzip input stream", e);
        }
    }
View Full Code Here

                    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));
                    if (log.isTraceEnabled())
                        log.trace(_loc.get("scan-found-names", clss, url));
                    names.addAll(Arrays.asList(clss));
                    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 = (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

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.