Example usage for org.apache.commons.compress.archivers.zip ZipFile getEntries

List of usage examples for org.apache.commons.compress.archivers.zip ZipFile getEntries

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.zip ZipFile getEntries.

Prototype

public Enumeration getEntries() 

Source Link

Document

Returns all entries.

Usage

From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java

@Test
public void testZipDirectoriesNotRecursive() throws Exception {
    FileUtils.forceMkdir(new File("target/Z-testfiles/source/subdir"));
    FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"),
            new File("target/Z-testfiles/source/CP0-input.csv"));
    FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"),
            new File("target/Z-testfiles/source/subdir/CP1-input.csv"));

    String aTargetFilename = "target/Z4-input.zip";
    ZipFilesTasklet aTasklet = new ZipFilesTasklet();
    aTasklet.setSourceBaseDirectory(new FileSystemResource("target/Z-testfiles/"));
    FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
    aSourceFactory.setPattern("file:target/Z-testfiles/source/");
    aTasklet.setSourceFactory(aSourceFactory);
    ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
    aDestinationFactory.setExpression(aTargetFilename);
    aTasklet.setDestinationFactory(aDestinationFactory);
    aTasklet.setRecursive(false);/*from  w  w w  .ja v  a 2  s .  c o  m*/

    assertFalse(new File(aTargetFilename).exists());

    StepContribution aStepContribution = mock(StepContribution.class);
    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
    verify(aStepContribution, times(2)).incrementReadCount();
    verify(aStepContribution, times(2)).incrementWriteCount(1);

    assertTrue(new File(aTargetFilename).exists());
    ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
    Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries();
    assertTrue(aEntries.hasMoreElements());
    assertEquals("source", aEntries.nextElement().getName());
    assertTrue(aEntries.hasMoreElements());
    assertEquals("source/CP0-input.csv", aEntries.nextElement().getName());
    assertFalse(aEntries.hasMoreElements());
    aZipFile.close();
}

From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java

@Test
public void testZipDirectory() throws Exception {
    FileUtils.forceMkdir(new File("target/Z-testfiles/source"));
    FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"),
            new File("target/Z-testfiles/source/CP0-input.csv"));
    FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"),
            new File("target/Z-testfiles/source/CP1-input.csv"));

    String aTargetFilename = "target/Z2-input.zip";
    ZipFilesTasklet aTasklet = new ZipFilesTasklet();
    aTasklet.setSourceBaseDirectory(new FileSystemResource("target/Z-testfiles/"));
    FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
    aSourceFactory.setPattern("file:target/Z-testfiles/source/");
    aTasklet.setSourceFactory(aSourceFactory);
    ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
    aDestinationFactory.setExpression(aTargetFilename);
    aTasklet.setDestinationFactory(aDestinationFactory);

    assertFalse(new File(aTargetFilename).exists());

    StepContribution aStepContribution = mock(StepContribution.class);
    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
    verify(aStepContribution, times(3)).incrementReadCount();
    verify(aStepContribution, times(3)).incrementWriteCount(1);

    assertTrue(new File(aTargetFilename).exists());
    ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
    Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries();
    assertTrue(aEntries.hasMoreElements());
    assertEquals("source", aEntries.nextElement().getName());
    assertTrue(aEntries.hasMoreElements());
    assertEquals("source/CP0-input.csv", aEntries.nextElement().getName());
    assertTrue(aEntries.hasMoreElements());
    assertEquals("source/CP1-input.csv", aEntries.nextElement().getName());
    assertFalse(aEntries.hasMoreElements());
    aZipFile.close();/*from w w w. ja  va2s  .c  o  m*/
}

From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java

@Test
public void testZipDirectories() throws Exception {
    FileUtils.forceMkdir(new File("target/Z-testfiles/source/subdir"));
    FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"),
            new File("target/Z-testfiles/source/CP0-input.csv"));
    FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"),
            new File("target/Z-testfiles/source/subdir/CP1-input.csv"));

    String aTargetFilename = "target/Z3-input.zip";
    ZipFilesTasklet aTasklet = new ZipFilesTasklet();
    aTasklet.setSourceBaseDirectory(new FileSystemResource("target/Z-testfiles/"));
    FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
    aSourceFactory.setPattern("file:target/Z-testfiles/source/");
    aTasklet.setSourceFactory(aSourceFactory);
    ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
    aDestinationFactory.setExpression(aTargetFilename);
    aTasklet.setDestinationFactory(aDestinationFactory);

    assertFalse(new File(aTargetFilename).exists());

    StepContribution aStepContribution = mock(StepContribution.class);
    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
    verify(aStepContribution, times(4)).incrementReadCount();
    verify(aStepContribution, times(4)).incrementWriteCount(1);

    assertTrue(new File(aTargetFilename).exists());
    ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
    Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries();
    assertTrue(aEntries.hasMoreElements());
    assertEquals("source", aEntries.nextElement().getName());
    assertTrue(aEntries.hasMoreElements());
    assertEquals("source/CP0-input.csv", aEntries.nextElement().getName());
    assertTrue(aEntries.hasMoreElements());
    assertEquals("source/subdir", aEntries.nextElement().getName());
    assertTrue(aEntries.hasMoreElements());
    assertEquals("source/subdir/CP1-input.csv", aEntries.nextElement().getName());
    assertFalse(aEntries.hasMoreElements());
    aZipFile.close();//from  w w w  . j av  a 2s. c  om
}

From source file:at.spardat.xma.xdelta.JarDelta.java

/**
 * Compute delta.//from w w  w .  ja  va  2 s.c om
 *
 * @param source the source
 * @param target the target
 * @param output the output
 * @param list the list
 * @param prefix the prefix
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void computeDelta(ZipFile source, ZipFile target, ZipArchiveOutputStream output, PrintWriter list,
        String prefix) throws IOException {
    try {
        for (Enumeration<ZipArchiveEntry> enumer = target.getEntries(); enumer.hasMoreElements();) {
            calculatedDelta = null;
            ZipArchiveEntry targetEntry = enumer.nextElement();
            ZipArchiveEntry sourceEntry = findBestSource(source, target, targetEntry);
            String nextEntryName = prefix + targetEntry.getName();
            if (sourceEntry != null && zipFilesPattern.matcher(sourceEntry.getName()).matches()
                    && !equal(sourceEntry, targetEntry)) {
                nextEntryName += "!";
            }
            nextEntryName += "|" + Long.toHexString(targetEntry.getCrc());
            if (sourceEntry != null) {
                nextEntryName += ":" + Long.toHexString(sourceEntry.getCrc());
            } else {
                nextEntryName += ":0";
            }
            list.println(nextEntryName);
            if (targetEntry.isDirectory()) {
                if (sourceEntry == null) {
                    ZipArchiveEntry outputEntry = entryToNewName(targetEntry, prefix + targetEntry.getName());
                    output.putArchiveEntry(outputEntry);
                    output.closeArchiveEntry();
                }
            } else {
                if (sourceEntry == null || sourceEntry.getSize() <= Delta.DEFAULT_CHUNK_SIZE
                        || targetEntry.getSize() <= Delta.DEFAULT_CHUNK_SIZE) { // new Entry od. alter Eintrag od. neuer Eintrag leer
                    ZipArchiveEntry outputEntry = entryToNewName(targetEntry, prefix + targetEntry.getName());
                    output.putArchiveEntry(outputEntry);
                    try (InputStream in = target.getInputStream(targetEntry)) {
                        int read = 0;
                        while (-1 < (read = in.read(buffer))) {
                            output.write(buffer, 0, read);
                        }
                        output.flush();
                    }
                    output.closeArchiveEntry();
                } else {
                    if (!equal(sourceEntry, targetEntry)) {
                        if (zipFilesPattern.matcher(sourceEntry.getName()).matches()) {
                            File embeddedTarget = File.createTempFile("jardelta-tmp", ".zip");
                            File embeddedSource = File.createTempFile("jardelta-tmp", ".zip");
                            try (FileOutputStream out = new FileOutputStream(embeddedSource);
                                    InputStream in = source.getInputStream(sourceEntry);
                                    FileOutputStream out2 = new FileOutputStream(embeddedTarget);
                                    InputStream in2 = target.getInputStream(targetEntry)) {
                                int read = 0;
                                while (-1 < (read = in.read(buffer))) {
                                    out.write(buffer, 0, read);
                                }
                                out.flush();
                                read = 0;
                                while (-1 < (read = in2.read(buffer))) {
                                    out2.write(buffer, 0, read);
                                }
                                out2.flush();
                                computeDelta(new ZipFile(embeddedSource), new ZipFile(embeddedTarget), output,
                                        list, prefix + sourceEntry.getName() + "!");
                            } finally {
                                embeddedSource.delete();
                                embeddedTarget.delete();
                            }
                        } else {
                            ZipArchiveEntry outputEntry = new ZipArchiveEntry(
                                    prefix + targetEntry.getName() + ".gdiff");
                            outputEntry.setTime(targetEntry.getTime());
                            outputEntry.setComment("" + targetEntry.getCrc());
                            output.putArchiveEntry(outputEntry);
                            if (calculatedDelta != null) {
                                output.write(calculatedDelta);
                                output.flush();
                            } else {
                                try (ByteArrayOutputStream outbytes = new ByteArrayOutputStream()) {
                                    Delta d = new Delta();
                                    DiffWriter diffWriter = new GDiffWriter(new DataOutputStream(outbytes));
                                    int sourceSize = (int) sourceEntry.getSize();
                                    byte[] sourceBytes = new byte[sourceSize];
                                    try (InputStream sourceStream = source.getInputStream(sourceEntry)) {
                                        for (int erg = sourceStream.read(
                                                sourceBytes); erg < sourceBytes.length; erg += sourceStream
                                                        .read(sourceBytes, erg, sourceBytes.length - erg))
                                            ;
                                    }
                                    d.compute(sourceBytes, target.getInputStream(targetEntry), diffWriter);
                                    output.write(outbytes.toByteArray());
                                }
                            }
                            output.closeArchiveEntry();
                        }
                    }
                }
            }
        }
    } finally {
        source.close();
        target.close();
    }
}

From source file:io.selendroid.builder.SelendroidServerBuilder.java

File createAndAddCustomizedAndroidManifestToSelendroidServer()
        throws IOException, ShellCommandException, AndroidSdkException {
    String targetPackageName = applicationUnderTest.getBasePackage();
    File tempdir = new File(FileUtils.getTempDirectoryPath() + File.separatorChar + targetPackageName
            + System.currentTimeMillis());

    if (!tempdir.exists()) {
        tempdir.mkdirs();/*w w  w.j a va  2 s.c o  m*/
    }

    File customizedManifest = new File(tempdir, "AndroidManifest.xml");
    log.info("Adding target package '" + targetPackageName + "' to " + customizedManifest.getAbsolutePath());

    // add target package
    InputStream inputStream = getResourceAsStream(selendroidApplicationXmlTemplate);
    if (inputStream == null) {
        throw new SelendroidException("AndroidApplication.xml template file was not found.");
    }
    String content = IOUtils.toString(inputStream, Charset.defaultCharset().displayName());

    // find the first occurance of "package" and appending the targetpackagename to begining
    int i = content.toLowerCase().indexOf("package");
    int cnt = 0;
    for (; i < content.length(); i++) {
        if (content.charAt(i) == '\"') {
            cnt++;
        }
        if (cnt == 2) {
            break;
        }
    }
    content = content.substring(0, i) + "." + targetPackageName + content.substring(i);
    log.info("Final Manifest File:\n" + content);
    content = content.replaceAll(SELENDROID_TEST_APP_PACKAGE, targetPackageName);
    // Seems like this needs to be done
    if (content.contains(ICON)) {
        content = content.replaceAll(ICON, "");
    }

    OutputStream outputStream = new FileOutputStream(customizedManifest);
    IOUtils.write(content, outputStream, Charset.defaultCharset().displayName());
    IOUtils.closeQuietly(inputStream);
    IOUtils.closeQuietly(outputStream);

    // adding the xml to an empty apk
    CommandLine createManifestApk = new CommandLine(AndroidSdk.aapt());

    createManifestApk.addArgument("package", false);
    createManifestApk.addArgument("-M", false);
    createManifestApk.addArgument(customizedManifest.getAbsolutePath(), false);
    createManifestApk.addArgument("-I", false);
    createManifestApk.addArgument(AndroidSdk.androidJar(), false);
    createManifestApk.addArgument("-F", false);
    createManifestApk.addArgument(tempdir.getAbsolutePath() + File.separatorChar + "manifest.apk", false);
    createManifestApk.addArgument("-f", false);
    log.info(ShellCommand.exec(createManifestApk, 20000L));

    ZipFile manifestApk = new ZipFile(
            new File(tempdir.getAbsolutePath() + File.separatorChar + "manifest.apk"));
    ZipArchiveEntry binaryManifestXml = manifestApk.getEntry("AndroidManifest.xml");

    File finalSelendroidServerFile = new File(tempdir.getAbsolutePath() + "selendroid-server.apk");
    ZipArchiveOutputStream finalSelendroidServer = new ZipArchiveOutputStream(finalSelendroidServerFile);
    finalSelendroidServer.putArchiveEntry(binaryManifestXml);
    IOUtils.copy(manifestApk.getInputStream(binaryManifestXml), finalSelendroidServer);

    ZipFile selendroidPrebuildApk = new ZipFile(selendroidServer.getAbsolutePath());
    Enumeration<ZipArchiveEntry> entries = selendroidPrebuildApk.getEntries();
    for (; entries.hasMoreElements();) {
        ZipArchiveEntry dd = entries.nextElement();
        finalSelendroidServer.putArchiveEntry(dd);

        IOUtils.copy(selendroidPrebuildApk.getInputStream(dd), finalSelendroidServer);
    }

    finalSelendroidServer.closeArchiveEntry();
    finalSelendroidServer.close();
    manifestApk.close();
    log.info("file: " + finalSelendroidServerFile.getAbsolutePath());
    return finalSelendroidServerFile;
}

From source file:autoupdater.FileDAO.java

/**
 * Unzips a zip archive.//from ww  w . ja v a 2s . co  m
 *
 * @param zip the zipfile to unzip
 * @param fileLocationOnDiskToDownloadTo the folder to unzip in
 * @return true if successful
 * @throws IOException
 */
public boolean unzipFile(ZipFile zip, File fileLocationOnDiskToDownloadTo) throws IOException {
    FileOutputStream dest = null;
    InputStream inStream = null;
    Enumeration<ZipArchiveEntry> zipFileEnum = zip.getEntries();
    while (zipFileEnum.hasMoreElements()) {
        ZipArchiveEntry entry = zipFileEnum.nextElement();
        File destFile = new File(fileLocationOnDiskToDownloadTo, entry.getName());
        if (!destFile.getParentFile().exists()) {
            if (!destFile.getParentFile().mkdirs()) {
                throw new IOException("could not create the folders to unzip in");
            }
        }
        if (!entry.isDirectory()) {
            try {
                dest = new FileOutputStream(destFile);
                inStream = zip.getInputStream(entry);
                IOUtils.copyLarge(inStream, dest);
            } finally {
                if (dest != null) {
                    dest.close();
                }
                if (inStream != null) {
                    inStream.close();
                }
            }
        } else {
            if (!destFile.exists()) {
                if (!destFile.mkdirs()) {
                    throw new IOException("could not create folders to unzip file");
                }
            }
        }
    }
    zip.close();
    return true;
}

From source file:de.catma.ui.repository.wizard.FileTypePanel.java

private ArrayList<SourceDocumentResult> makeSourceDocumentResultsFromInputFile(TechInfoSet inputTechInfoSet)
        throws MalformedURLException, IOException {

    ArrayList<SourceDocumentResult> output = new ArrayList<SourceDocumentResult>();

    FileType inputFileType = FileType.getFileType(inputTechInfoSet.getMimeType());

    if (inputFileType != FileType.ZIP) {
        SourceDocumentResult outputSourceDocumentResult = new SourceDocumentResult();

        String sourceDocumentID = repository.getIdFromURI(inputTechInfoSet.getURI());
        outputSourceDocumentResult.setSourceDocumentID(sourceDocumentID);

        SourceDocumentInfo outputSourceDocumentInfo = outputSourceDocumentResult.getSourceDocumentInfo();
        outputSourceDocumentInfo.setTechInfoSet(new TechInfoSet(inputTechInfoSet));
        outputSourceDocumentInfo.setContentInfoSet(new ContentInfoSet());

        outputSourceDocumentInfo.getTechInfoSet().setFileType(inputFileType);

        output.add(outputSourceDocumentResult);
    } else { //TODO: put this somewhere sensible
        URI uri = inputTechInfoSet.getURI();
        ZipFile zipFile = new ZipFile(uri.getPath());
        Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();

        String tempDir = ((CatmaApplication) UI.getCurrent()).getTempDirectory();
        IDGenerator idGenerator = new IDGenerator();

        while (entries.hasMoreElements()) {
            ZipArchiveEntry entry = entries.nextElement();
            String fileName = FilenameUtils.getName(entry.getName());
            String fileId = idGenerator.generate();

            File entryDestination = new File(tempDir, fileId);
            if (entryDestination.exists()) {
                entryDestination.delete();
            }//from w  w w  .  j  a v  a  2  s.  c  o m

            entryDestination.getParentFile().mkdirs();
            if (entry.isDirectory()) {
                entryDestination.mkdirs();
            } else {
                BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(entryDestination));
                IOUtils.copy(bis, bos);
                IOUtils.closeQuietly(bis);
                IOUtils.closeQuietly(bos);

                SourceDocumentResult outputSourceDocumentResult = new SourceDocumentResult();
                URI newURI = entryDestination.toURI();

                String repositoryId = repository.getIdFromURI(newURI); // we need to do this as a catma:// is appended

                outputSourceDocumentResult.setSourceDocumentID(repositoryId);

                SourceDocumentInfo outputSourceDocumentInfo = outputSourceDocumentResult
                        .getSourceDocumentInfo();
                TechInfoSet newTechInfoSet = new TechInfoSet(fileName, null, newURI); // TODO: MimeType detection ?
                FileType newFileType = FileType.getFileTypeFromName(fileName);
                newTechInfoSet.setFileType(newFileType);

                outputSourceDocumentInfo.setTechInfoSet(newTechInfoSet);
                outputSourceDocumentInfo.setContentInfoSet(new ContentInfoSet());

                output.add(outputSourceDocumentResult);
            }
        }

        ZipFile.closeQuietly(zipFile);
    }

    for (SourceDocumentResult sdr : output) {
        TechInfoSet sdrTechInfoSet = sdr.getSourceDocumentInfo().getTechInfoSet();
        String sdrSourceDocumentId = sdr.getSourceDocumentID();

        ProtocolHandler protocolHandler = getProtocolHandlerForUri(sdrTechInfoSet.getURI(), sdrSourceDocumentId,
                sdrTechInfoSet.getMimeType());
        String mimeType = protocolHandler.getMimeType();

        sdrTechInfoSet.setMimeType(mimeType);
        FileType sdrFileType = FileType.getFileType(mimeType);
        sdrTechInfoSet.setFileType(sdrFileType);

        if (sdrFileType.isCharsetSupported()) {
            Charset charset = Charset.forName(protocolHandler.getEncoding());
            sdrTechInfoSet.setCharset(charset);
        } else {
            sdrTechInfoSet.setFileOSType(FileOSType.INDEPENDENT);
        }

        loadSourceDocumentAndContent(sdr);
    }

    return output;
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftExporterBeanTest.java

@Test
public void testExportArchiveZip() throws Exception {
    final Project p = makeGoodProject();
    final List<PackagingInfo> infos = this.bean.getAvailablePackagingInfos(p);
    final PackagingInfo zipPi = Iterables.find(infos, new Predicate<PackagingInfo>() {
        @Override//from   w w  w.ja v a 2s.c  o m
        public boolean apply(PackagingInfo t) {
            return t.getMethod() == PackagingInfo.PackagingMethod.ZIP;
        }
    });
    final File f = File.createTempFile("test", zipPi.getName());
    final FileOutputStream fos = new FileOutputStream(f);

    this.bean.export(p, "http://example.com/my_experiemnt", PackagingInfo.PackagingMethod.ZIP, fos);
    fos.close();
    final ZipFile zf = new ZipFile(f);
    final Enumeration<ZipArchiveEntry> en = zf.getEntries();
    final Set<String> entries = new HashSet<String>();
    entries.addAll(java.util.Arrays.asList("test-exp-id.soft.txt", "raw_file.data", "derived_file.data",
            "supplimental.data"));
    while (en.hasMoreElements()) {
        final ZipArchiveEntry ze = en.nextElement();
        assertTrue(ze.getName() + " unexpected", entries.remove(ze.getName()));

    }
    assertTrue(entries.toString() + " not found", entries.isEmpty());
}

From source file:io.selendroid.standalone.builder.SelendroidServerBuilder.java

File createAndAddCustomizedAndroidManifestToSelendroidServer()
        throws IOException, ShellCommandException, AndroidSdkException {
    String targetPackageName = applicationUnderTest.getBasePackage();

    File tmpDir = Files.createTempDir();
    if (deleteTmpFiles()) {
        tmpDir.deleteOnExit();//from  w w w.j av  a 2  s .  c  o m
    }

    File customizedManifest = new File(tmpDir, "AndroidManifest.xml");
    if (deleteTmpFiles()) {
        customizedManifest.deleteOnExit();
    }
    log.info("Adding target package '" + targetPackageName + "' to " + customizedManifest.getAbsolutePath());

    // add target package
    InputStream inputStream = getResourceAsStream(selendroidApplicationXmlTemplate);
    if (inputStream == null) {
        throw new SelendroidException("AndroidApplication.xml template file was not found.");
    }
    String content = IOUtils.toString(inputStream, Charset.defaultCharset().displayName());

    // find the first occurance of "package" and appending the targetpackagename to begining
    int i = content.toLowerCase().indexOf("package");
    int cnt = 0;
    for (; i < content.length(); i++) {
        if (content.charAt(i) == '\"') {
            cnt++;
        }
        if (cnt == 2) {
            break;
        }
    }
    content = content.substring(0, i) + "." + targetPackageName + content.substring(i);
    log.info("Final Manifest File:\n" + content);
    content = content.replaceAll(SELENDROID_TEST_APP_PACKAGE, targetPackageName);
    // Seems like this needs to be done
    if (content.contains(ICON)) {
        content = content.replaceAll(ICON, "");
    }

    OutputStream outputStream = new FileOutputStream(customizedManifest);
    IOUtils.write(content, outputStream, Charset.defaultCharset().displayName());
    IOUtils.closeQuietly(inputStream);
    IOUtils.closeQuietly(outputStream);

    // adding the xml to an empty apk
    CommandLine createManifestApk = new CommandLine(AndroidSdk.aapt());

    File manifestApkFile = File.createTempFile("manifest", ".apk");
    if (deleteTmpFiles()) {
        manifestApkFile.deleteOnExit();
    }

    createManifestApk.addArgument("package", false);
    createManifestApk.addArgument("-M", false);
    createManifestApk.addArgument(customizedManifest.getAbsolutePath(), false);
    createManifestApk.addArgument("-I", false);
    createManifestApk.addArgument(AndroidSdk.androidJar(), false);
    createManifestApk.addArgument("-F", false);
    createManifestApk.addArgument(manifestApkFile.getAbsolutePath(), false);
    createManifestApk.addArgument("-f", false);
    log.info(ShellCommand.exec(createManifestApk, 20000L));

    ZipFile manifestApk = new ZipFile(manifestApkFile);
    ZipArchiveEntry binaryManifestXml = manifestApk.getEntry("AndroidManifest.xml");

    File finalSelendroidServerFile = File.createTempFile("selendroid-server", ".apk");
    if (deleteTmpFiles()) {
        finalSelendroidServerFile.deleteOnExit();
    }

    ZipArchiveOutputStream finalSelendroidServer = new ZipArchiveOutputStream(finalSelendroidServerFile);
    finalSelendroidServer.putArchiveEntry(binaryManifestXml);
    IOUtils.copy(manifestApk.getInputStream(binaryManifestXml), finalSelendroidServer);

    ZipFile selendroidPrebuildApk = new ZipFile(selendroidServer.getAbsolutePath());
    Enumeration<ZipArchiveEntry> entries = selendroidPrebuildApk.getEntries();
    for (; entries.hasMoreElements();) {
        ZipArchiveEntry dd = entries.nextElement();
        finalSelendroidServer.putArchiveEntry(dd);

        IOUtils.copy(selendroidPrebuildApk.getInputStream(dd), finalSelendroidServer);
    }

    finalSelendroidServer.closeArchiveEntry();
    finalSelendroidServer.close();
    manifestApk.close();
    log.info("file: " + finalSelendroidServerFile.getAbsolutePath());
    return finalSelendroidServerFile;
}

From source file:at.spardat.xma.xdelta.test.JarDeltaJarPatcherTest.java

/**
 * Compares the content of two zip files. The zip files are considered equal, if
 * the content of all zip entries is equal to the content of its corresponding entry
 * in the other zip file./* w  w  w  .  ja v  a  2s  .  c o  m*/
 *
 * @author S3460
 * @param zipSource the zip source
 * @param resultZip the result zip
 * @throws Exception the exception
 */
private void compareFiles(ZipFile zipSource, ZipFile resultZip) throws Exception {
    boolean rc = false;
    try {
        for (Enumeration<ZipArchiveEntry> enumer = zipSource.getEntries(); enumer.hasMoreElements();) {
            ZipArchiveEntry sourceEntry = enumer.nextElement();
            ZipArchiveEntry resultEntry = resultZip.getEntry(sourceEntry.getName());
            assertNotNull("Entry nicht generiert: " + sourceEntry.getName(), resultEntry);
            byte[] oldBytes = toBytes(zipSource, sourceEntry);
            byte[] newBytes = toBytes(resultZip, resultEntry);
            rc = equal(oldBytes, newBytes);
            assertTrue("bytes the same " + sourceEntry, rc);
        }
    } finally {
        zipSource.close();
        resultZip.close();
    }
}