blob: 0f2865b6a3bcb92efe98f33763fbf9908d347fdc [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 compeople AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* compeople AG (Stefan Liebig) - initial API and implementation
* IBM Corporation - ongoing development
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.processors.jbdiff;
import ie.wombat.jbdiff.JBPatch;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.eclipse.equinox.p2.artifact.repository.ArtifactDescriptor;
import org.eclipse.equinox.p2.sar.DirectByteArrayOutputStream;
import org.eclipse.equinox.p2.sar.SarUtil;
/**
* The <code>JBPatchZipStep</code> patches a JBDiff based diff of zips/jars.
*/
public class JBPatchZipStep extends JBPatchStep {
public JBPatchZipStep() {
super();
}
protected void performProcessing() throws IOException {
DirectByteArrayOutputStream predecessor = fetchPredecessorBytes(new ArtifactDescriptor(key));
DirectByteArrayOutputStream current = (DirectByteArrayOutputStream) incomingStream;
byte[] result = JBPatch.bspatch(predecessor.getBuffer(), predecessor.getBufferLength(), current.getBuffer(), current.getBufferLength());
// free up the memory as soon as possible.
predecessor = null;
current = null;
incomingStream = null;
// copy the result of the optimization to the destination.
SarUtil.sarToZip(new ByteArrayInputStream(result), true, destination, false);
}
private DirectByteArrayOutputStream fetchPredecessorBytes(ArtifactDescriptor artifactDescriptor) throws IOException {
DirectByteArrayOutputStream zippedPredecessor = new DirectByteArrayOutputStream();
status = repository.getArtifact(artifactDescriptor, zippedPredecessor, monitor);
if (!status.isOK())
throw (IOException) new IOException(status.getMessage()).initCause(status.getException());
DirectByteArrayOutputStream result = new DirectByteArrayOutputStream();
SarUtil.zipToSar(zippedPredecessor.getInputStream(), result);
return result;
}
}