Search in sources :

Example 81 with ZipEntry

use of java.util.zip.ZipEntry in project Fairphone by Kwamecorp.

the class GappsInstallerHelper method unzip.

public void unzip(String filePath, String targetPath) {
    new File(targetPath).mkdirs();
    try {
        FileInputStream fin = new FileInputStream(filePath);
        ZipInputStream zin = new ZipInputStream(fin);
        ZipEntry ze = null;
        while ((ze = zin.getNextEntry()) != null) {
            Log.d(TAG, "Unzipping " + ze.getName());
            if (ze.isDirectory()) {
                _dirChecker(ze.getName(), targetPath);
            } else {
                FileOutputStream fout = new FileOutputStream(targetPath + ze.getName());
                byte[] buffer = new byte[2048];
                int count = 0;
                while ((count = zin.read(buffer)) != -1) {
                    fout.write(buffer, 0, count);
                }
                zin.closeEntry();
                fout.close();
            }
        }
        zin.close();
        fin.close();
    } catch (Exception e) {
        Log.e("Decompress", "unzip", e);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) TimeoutException(java.util.concurrent.TimeoutException) RootDeniedException(com.stericson.RootTools.exceptions.RootDeniedException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 82 with ZipEntry

use of java.util.zip.ZipEntry in project Fairphone by Kwamecorp.

the class RSAUtils method unzip.

private static void unzip(String filePath, String targetPath) {
    new File(targetPath).mkdirs();
    try {
        FileInputStream fin = new FileInputStream(filePath);
        ZipInputStream zin = new ZipInputStream(fin);
        ZipEntry ze = null;
        while ((ze = zin.getNextEntry()) != null) {
            Log.d(TAG, "Unzipping " + ze.getName());
            if (ze.isDirectory()) {
                _dirChecker(ze.getName(), targetPath);
            } else {
                FileOutputStream fout = new FileOutputStream(targetPath + ze.getName());
                byte[] buffer = new byte[2048];
                int count = 0;
                while ((count = zin.read(buffer)) != -1) {
                    fout.write(buffer, 0, count);
                }
                zin.closeEntry();
                fout.close();
            }
        }
        zin.close();
        fin.close();
    } catch (Exception e) {
        Log.e("Decompress", "unzip", e);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 83 with ZipEntry

use of java.util.zip.ZipEntry in project MinecraftForge by MinecraftForge.

the class AccessTransformer method processJar.

private static void processJar(File inFile, File outFile, AccessTransformer[] transformers) throws IOException {
    ZipInputStream inJar = null;
    ZipOutputStream outJar = null;
    try {
        try {
            inJar = new ZipInputStream(new BufferedInputStream(new FileInputStream(inFile)));
        } catch (FileNotFoundException e) {
            throw new FileNotFoundException("Could not open input file: " + e.getMessage());
        }
        try {
            outJar = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
        } catch (FileNotFoundException e) {
            throw new FileNotFoundException("Could not open output file: " + e.getMessage());
        }
        ZipEntry entry;
        while ((entry = inJar.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                outJar.putNextEntry(entry);
                continue;
            }
            byte[] data = new byte[4096];
            ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream();
            int len;
            do {
                len = inJar.read(data);
                if (len > 0) {
                    entryBuffer.write(data, 0, len);
                }
            } while (len != -1);
            byte[] entryData = entryBuffer.toByteArray();
            String entryName = entry.getName();
            if (entryName.endsWith(".class") && !entryName.startsWith(".")) {
                ClassNode cls = new ClassNode();
                ClassReader rdr = new ClassReader(entryData);
                rdr.accept(cls, 0);
                String name = cls.name.replace('/', '.').replace('\\', '.');
                for (AccessTransformer trans : transformers) {
                    entryData = trans.transform(name, name, entryData);
                }
            }
            ZipEntry newEntry = new ZipEntry(entryName);
            outJar.putNextEntry(newEntry);
            outJar.write(entryData);
        }
    } finally {
        IOUtils.closeQuietly(outJar);
        IOUtils.closeQuietly(inJar);
    }
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ClassReader(org.objectweb.asm.ClassReader) BufferedOutputStream(java.io.BufferedOutputStream)

Example 84 with ZipEntry

use of java.util.zip.ZipEntry in project MinecraftForge by MinecraftForge.

the class MarkerTransformer method processJar.

private static void processJar(File inFile, File outFile, MarkerTransformer[] transformers) throws IOException {
    ZipInputStream inJar = null;
    ZipOutputStream outJar = null;
    try {
        try {
            inJar = new ZipInputStream(new BufferedInputStream(new FileInputStream(inFile)));
        } catch (FileNotFoundException e) {
            throw new FileNotFoundException("Could not open input file: " + e.getMessage());
        }
        try {
            outJar = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
        } catch (FileNotFoundException e) {
            throw new FileNotFoundException("Could not open output file: " + e.getMessage());
        }
        ZipEntry entry;
        while ((entry = inJar.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                outJar.putNextEntry(entry);
                continue;
            }
            byte[] data = new byte[4096];
            ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream();
            int len;
            do {
                len = inJar.read(data);
                if (len > 0) {
                    entryBuffer.write(data, 0, len);
                }
            } while (len != -1);
            byte[] entryData = entryBuffer.toByteArray();
            String entryName = entry.getName();
            if (entryName.endsWith(".class") && !entryName.startsWith(".")) {
                ClassNode cls = new ClassNode();
                ClassReader rdr = new ClassReader(entryData);
                rdr.accept(cls, 0);
                String name = cls.name.replace('/', '.').replace('\\', '.');
                for (MarkerTransformer trans : transformers) {
                    entryData = trans.transform(name, name, entryData);
                }
            }
            ZipEntry newEntry = new ZipEntry(entryName);
            outJar.putNextEntry(newEntry);
            outJar.write(entryData);
        }
    } finally {
        IOUtils.closeQuietly(outJar);
        IOUtils.closeQuietly(inJar);
    }
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ClassReader(org.objectweb.asm.ClassReader) BufferedOutputStream(java.io.BufferedOutputStream)

Example 85 with ZipEntry

use of java.util.zip.ZipEntry in project OpenGrok by OpenGrok.

the class JarAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    try (ZipInputStream zis = new ZipInputStream(src.getStream())) {
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            String ename = entry.getName();
            if (xrefOut != null) {
                xrefOut.append("<br/><b>");
                Util.htmlize(ename, xrefOut);
                xrefOut.append("</b>");
            }
            doc.add(new TextField("full", ename, Store.NO));
            FileAnalyzerFactory fac = AnalyzerGuru.find(ename);
            if (fac instanceof JavaClassAnalyzerFactory) {
                if (xrefOut != null) {
                    xrefOut.append("<br/>");
                }
                JavaClassAnalyzer jca = (JavaClassAnalyzer) fac.getAnalyzer();
                jca.analyze(doc, new BufferedInputStream(zis), xrefOut);
            }
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) FileAnalyzerFactory(org.opensolaris.opengrok.analysis.FileAnalyzerFactory) ZipEntry(java.util.zip.ZipEntry) TextField(org.apache.lucene.document.TextField)

Aggregations

ZipEntry (java.util.zip.ZipEntry)1367 ZipFile (java.util.zip.ZipFile)479 File (java.io.File)469 IOException (java.io.IOException)361 ZipOutputStream (java.util.zip.ZipOutputStream)321 ZipInputStream (java.util.zip.ZipInputStream)300 InputStream (java.io.InputStream)282 FileOutputStream (java.io.FileOutputStream)278 FileInputStream (java.io.FileInputStream)270 Test (org.junit.Test)124 BufferedInputStream (java.io.BufferedInputStream)122 JarFile (java.util.jar.JarFile)122 BufferedOutputStream (java.io.BufferedOutputStream)99 ByteArrayOutputStream (java.io.ByteArrayOutputStream)97 ArrayList (java.util.ArrayList)84 ByteArrayInputStream (java.io.ByteArrayInputStream)78 OutputStream (java.io.OutputStream)67 JarOutputStream (java.util.jar.JarOutputStream)59 Path (java.nio.file.Path)56 Enumeration (java.util.Enumeration)56