Example usage for org.apache.commons.compress.changes ChangeSet add

List of usage examples for org.apache.commons.compress.changes ChangeSet add

Introduction

In this page you can find the example usage for org.apache.commons.compress.changes ChangeSet add.

Prototype

public void add(final ArchiveEntry pEntry, final InputStream pInput) 

Source Link

Document

Adds a new archive entry to the archive.

Usage

From source file:org.obm.sync.ObmSyncArchiveUtils.java

private static File[] replaceServiceJar(File[] asFile) {
    return FluentIterable.from(Arrays.asList(asFile)).transform(new Function<File, File>() {

        @Override//from  w w  w  .j  ava 2s.  c  o m
        public File apply(File input) {
            if (input.getName().contains("services-module")) {
                ZipFile servicesZip = null;
                try {
                    File outputFile = File.createTempFile("services-module", ".jar");
                    servicesZip = new ZipFile(input);

                    ChangeSet changeSet = new ChangeSet();
                    changeSet.add(new JarArchiveEntry("META-INF/MANIFEST.MF"),
                            ClassLoader.getSystemClassLoader().getResourceAsStream("MANIFEST.MF"));
                    ChangeSetPerformer changeSetPerformer = new ChangeSetPerformer(changeSet);
                    JarArchiveOutputStream jarArchiveOutputStream = new JarArchiveOutputStream(
                            new FileOutputStream(outputFile));
                    changeSetPerformer.perform(servicesZip, jarArchiveOutputStream);
                    return outputFile;
                } catch (IOException e) {
                    Throwables.propagate(e);
                } finally {
                    try {
                        if (servicesZip != null) {
                            servicesZip.close();
                        }
                    } catch (IOException e) {
                        Throwables.propagate(e);
                    }
                }
            }
            return input;
        }
    }).toArray(File.class);
}