Package de.schlichtherle.util.zip

Examples of de.schlichtherle.util.zip.BasicZipFile


        // Delete any remnants of this expanded profile
        if (destination.exists()) {
            FileUtils.deleteDirectory(destination);
        }

        BasicZipFile zip = new BasicZipFile(source);
       
        try {
            // count the zip entries so we can do progress bar
            long totalSize = 0L;
            for (Enumeration<? extends ZipEntry> it = zip.entries(); it
                    .hasMoreElements();) {
                ZipEntry e = it.nextElement();
                totalSize += e.getSize();
            }

            long bytesSoFar = 0L;
            for (Enumeration<? extends ZipEntry> it = zip.entries(); it
                    .hasMoreElements();) {
                ZipEntry entry = it.nextElement();
               
                // zip entries can be created on windows or unix, and can retain
                // the path separator for that platform.  We must ensure that
                // the paths we find inside the zip file will work on the platform
                // we are running on.  Technically, zip entry paths should be
                // created using the unix separator, no matter what platform they
                // are created on - but this is not always done correctly.
                final String entryName = getPlatformSpecificPath(entry.getName());
               
                File expandedFile = new File(destination + File.separator
                        + entryName);

                BufferedInputStream in = new BufferedInputStream(zip
                        .getInputStream(entry));

                FileUtils.forceMkdir(expandedFile.getParentFile());
                BufferedOutputStream out = new BufferedOutputStream(
                        new FileOutputStream(expandedFile));

                bytesSoFar = readFile(in, out, observer, bytesSoFar, totalSize);
            }
            observer.onProgress(UNITY_PERCENT);
        } finally {
            zip.close();
        }

    }
View Full Code Here


     * {@inheritDoc}
     */
    @Override
    public void handle(IdentificationRequest request) throws IOException {
       
        final BasicZipFile zipFile = new BasicZipFile(request.getSourceFile());
        try {
            Iterable<ZipEntry> iterable = new Iterable<ZipEntry>() {
                @Override
                public final Iterator<ZipEntry> iterator() {
                    return new ZipFileIterator(zipFile);
                }
            };
   
            ZipArchiveWalker walker = new ZipArchiveWalker(request.getIdentifier(), zipFile)
            walker.walk(iterable);
        } finally {
            if (zipFile != null) {
                zipFile.close();
            }
        }
    }
View Full Code Here

*/
public class ZipIdentifierEngine extends AbstractIdentifierEngine {

    @Override
    public void process(IdentificationRequest request, ContainerSignatureMatchCollection matches) throws IOException {
        BasicZipFile zipFile = new BasicZipFile(request.getSourceFile());
        try {
            // For each entry:
            for (String entryName : matches.getAllFileEntries()) {
                final ZipEntry entry = zipFile.getEntry(entryName);
                if (entry != null) {
                    // Get a stream for the entry and a byte reader over the stream:
                    InputStream stream = zipFile.getInputStream(entry);
                    ByteReader reader = null;
                    try {
                        reader = newByteReader(stream);
                        // For each signature to match:
                        List<ContainerSignatureMatch> matchList = matches.getContainerSignatureMatches();
                        for (ContainerSignatureMatch match : matchList) {
                            match.matchBinaryContent(entryName, reader);
                        }
                    } finally {
                        if (reader != null) {
                            reader.close();
                        }
                        if (stream != null) {
                            stream.close();
                        }
                    }
                }
            }
        } finally {
            zipFile.close();
        }
       
        //
       
       
View Full Code Here

TOP

Related Classes of de.schlichtherle.util.zip.BasicZipFile

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.