src/main/java/at/spardat/xma/xdelta/JarPatcher.java
public void applyDelta(ZipFile source, ZipFile patch, ZipOutputStream output) throws IOException {
        try {
            ZipEntry listEntry = patch.getEntry("META-INF/file.list");
            if(listEntry==null) {
                throw new FileNotFoundException("META-INF/file.list");
            }
            BufferedReader list = new BufferedReader(new InputStreamReader(patch.getInputStream(listEntry)));
            for(String fileName=list.readLine();fileName!=null;fileName=list.readLine()) {
                if("META-INF/file.list".equalsIgnoreCase(fileName)) continue;
                ZipEntry patchEntry = patch.getEntry(fileName);
                if(patchEntry!=null) { // new Entry
                    if(patchEntry.isDirectory()) {
                        ZipEntry outputEntry = new ZipEntry(patchEntry);
                        output.putNextEntry(outputEntry);
                        continue;
                    } else {
                        byte[] patchBytes = new byte[(int)patchEntry.getSize()];
                        InputStream patchStream = patch.getInputStream(patchEntry);
                        for(int erg=patchStream.read(patchBytes);erg<patchBytes.length;erg+=patchStream.read(patchBytes,erg,patchBytes.length-erg));
                        patchStream.close();
                        ZipEntry outputEntry = new ZipEntry(patchEntry);
                        output.putNextEntry(outputEntry);
                        output.write(patchBytes);
                    }
                } else {
                    ZipEntry sourceEntry = source.getEntry(fileName);
                    if(sourceEntry == null) {
                        throw new FileNotFoundException(fileName+" not found in "+source.getName()+" or "+patch.getName());
                    }
                    if(sourceEntry.isDirectory()) {
                        ZipEntry outputEntry = new ZipEntry(sourceEntry);
                        output.putNextEntry(outputEntry);
                        continue;
                    }
                    byte[] sourceBytes = new byte[(int)sourceEntry.getSize()];
                    InputStream sourceStream = source.getInputStream(sourceEntry);
                    for(int erg=sourceStream.read(sourceBytes);erg<sourceBytes.length;erg+=sourceStream.read(sourceBytes,erg,sourceBytes.length-erg));
                    sourceStream.close();

                    patchEntry = patch.getEntry(fileName+".gdiff");
                    if(patchEntry!=null) { // changed Entry
                        ZipEntry outputEntry = new ZipEntry(sourceEntry.getName());
                        outputEntry.setTime(patchEntry.getTime());
                        output.putNextEntry(outputEntry);
                        
                        InputStream patchStream = patch.getInputStream(patchEntry);
                        GDiffPatcher diffPatcher = new GDiffPatcher();
                        diffPatcher.patch(sourceBytes,patchStream,output);
                        patchStream.close();

                    } else { // unchanged Entry
                        ZipEntry outputEntry = new ZipEntry(sourceEntry);
                        output.putNextEntry(outputEntry);
                        output.write(sourceBytes);
                    }
                }
                output.closeEntry(); //nach jedem: output.putNextEntry() + output.write()
            }
            list.close();
        } catch (PatchException pe) {
            IOException ioe = new IOException();
            ioe.initCause(pe);
            throw ioe;
        } finally {
            source.close();
            patch.close();
            output.close();
        }
    }
/**
     * Applies the differences in patch to source to create the target file. All binary difference files
     * are applied to their corresponding file in source using {@link com.nothome.delta.GDiffPatcher}.
     * All other files listed in <code>META-INF/file.list</code> are copied from patch to output.
     *
     * @param source the original zip file, where the patches have to be applied
     * @param patch a zip file created by {@link JarDelta#computeDelta(ZipFile, ZipFile, ZipOutputStream)}
     *        containing the patches to apply
     * @param output the patched zip file to create
     * @throws IOException if an error occures reading or writing any entry in a zip file
     */
Applies the differences in patch to source to create the target file. All binary difference files
are applied to their corresponding file in source using  com.nothome.delta.GDiffPatcher.
All other files listed in META-INF/file.list are copied from patch to output.

@param source the original zip file, where the patches have to be applied
@param patch a zip file created by  JarDelta#computeDelta(ZipFile, ZipFile, ZipOutputStream)
containing the patches to apply
@param output the patched zip file to create
@throws IOException if an error occures reading or writing any entry in a zip file
Applies the differences in patch to source to create the target file . All binary difference files are applied to their corresponding file in source using com . nothome . delta . GDiffPatcher . All other files listed in META - INF / file . list are copied from patch to output . @param source the original zip file where the patches have to be applied @param patch a zip file created by JarDelta#computeDelta ( ZipFile ZipFile ZipOutputStream ) containing the patches to apply @param output the patched zip file to create @throws IOException if an error occures reading or writing any entry in a zip file
public void applyDelta(ZipFile source, ZipFile patch, ZipOutputStream output) throws IOException {
        try {
            ZipEntry listEntry = patch.getEntry("META-INF/file.list");
            if(listEntry==null) {
                throw new FileNotFoundException("META-INF/file.list");
            }
            BufferedReader list = new BufferedReader(new InputStreamReader(patch.getInputStream(listEntry)));
            for(String fileName=list.readLine();fileName!=null;fileName=list.readLine()) {
                if("META-INF/file.list".equalsIgnoreCase(fileName)) continue;
                ZipEntry patchEntry = patch.getEntry(fileName);
                if(patchEntry!=null) { 
                    if(patchEntry.isDirectory()) {
                        ZipEntry outputEntry = new ZipEntry(patchEntry);
                        output.putNextEntry(outputEntry);
                        continue;
                    } else {
                        byte[] patchBytes = new byte[(int)patchEntry.getSize()];
                        InputStream patchStream = patch.getInputStream(patchEntry);
                        for(int erg=patchStream.read(patchBytes);erg<patchBytes.length;erg+=patchStream.read(patchBytes,erg,patchBytes.length-erg));
                        patchStream.close();
                        ZipEntry outputEntry = new ZipEntry(patchEntry);
                        output.putNextEntry(outputEntry);
                        output.write(patchBytes);
                    }
                } else {
                    ZipEntry sourceEntry = source.getEntry(fileName);
                    if(sourceEntry == null) {
                        throw new FileNotFoundException(fileName+" not found in "+source.getName()+" or "+patch.getName());
                    }
                    if(sourceEntry.isDirectory()) {
                        ZipEntry outputEntry = new ZipEntry(sourceEntry);
                        output.putNextEntry(outputEntry);
                        continue;
                    }
                    byte[] sourceBytes = new byte[(int)sourceEntry.getSize()];
                    InputStream sourceStream = source.getInputStream(sourceEntry);
                    for(int erg=sourceStream.read(sourceBytes);erg<sourceBytes.length;erg+=sourceStream.read(sourceBytes,erg,sourceBytes.length-erg));
                    sourceStream.close();
                    patchEntry = patch.getEntry(fileName+".gdiff");
                    if(patchEntry!=null) { 
                        ZipEntry outputEntry = new ZipEntry(sourceEntry.getName());
                        outputEntry.setTime(patchEntry.getTime());
                        output.putNextEntry(outputEntry);
                        InputStream patchStream = patch.getInputStream(patchEntry);
                        GDiffPatcher diffPatcher = new GDiffPatcher();
                        diffPatcher.patch(sourceBytes,patchStream,output);
                        patchStream.close();
                    } else { 
                        ZipEntry outputEntry = new ZipEntry(sourceEntry);
                        output.putNextEntry(outputEntry);
                        output.write(sourceBytes);
                    }
                }
                output.closeEntry(); 
            }
            list.close();
        } catch (PatchException pe) {
            IOException ioe = new IOException();
            ioe.initCause(pe);
            throw ioe;
        } finally {
            source.close();
            patch.close();
            output.close();
        }
    }
public void applyDelta ( ZipFile source , ZipFile patch , ZipOutputStream output ) throws IOException { try { ZipEntry listEntry = patch . getEntry ( "META-INF/file.list" ) ; if ( listEntry == null ) { throw new FileNotFoundException ( "META-INF/file.list" ) ; } BufferedReader list = new BufferedReader ( new InputStreamReader ( patch . getInputStream ( listEntry ) ) ) ; for ( String fileName = list . readLine ( ) ; fileName != null ; fileName = list . readLine ( ) ) { if ( "META-INF/file.list" . equalsIgnoreCase ( fileName ) ) continue ; ZipEntry patchEntry = patch . getEntry ( fileName ) ; if ( patchEntry != null ) { if ( patchEntry . isDirectory ( ) ) { ZipEntry outputEntry = new ZipEntry ( patchEntry ) ; output . putNextEntry ( outputEntry ) ; continue ; } else { byte [ ] patchBytes = new byte [ ( int ) patchEntry . getSize ( ) ] ; InputStream patchStream = patch . getInputStream ( patchEntry ) ; for ( int erg = patchStream . read ( patchBytes ) ; erg < patchBytes . length ; erg += patchStream . read ( patchBytes , erg , patchBytes . length - erg ) ) ; patchStream . close ( ) ; ZipEntry outputEntry = new ZipEntry ( patchEntry ) ; output . putNextEntry ( outputEntry ) ; output . write ( patchBytes ) ; } } else { ZipEntry sourceEntry = source . getEntry ( fileName ) ; if ( sourceEntry == null ) { throw new FileNotFoundException ( fileName + " not found in " + source . getName ( ) + " or " + patch . getName ( ) ) ; } if ( sourceEntry . isDirectory ( ) ) { ZipEntry outputEntry = new ZipEntry ( sourceEntry ) ; output . putNextEntry ( outputEntry ) ; continue ; } byte [ ] sourceBytes = new byte [ ( int ) sourceEntry . getSize ( ) ] ; InputStream sourceStream = source . getInputStream ( sourceEntry ) ; for ( int erg = sourceStream . read ( sourceBytes ) ; erg < sourceBytes . length ; erg += sourceStream . read ( sourceBytes , erg , sourceBytes . length - erg ) ) ; sourceStream . close ( ) ; patchEntry = patch . getEntry ( fileName + ".gdiff" ) ; if ( patchEntry != null ) { ZipEntry outputEntry = new ZipEntry ( sourceEntry . getName ( ) ) ; outputEntry . setTime ( patchEntry . getTime ( ) ) ; output . putNextEntry ( outputEntry ) ; InputStream patchStream = patch . getInputStream ( patchEntry ) ; GDiffPatcher diffPatcher = new GDiffPatcher ( ) ; diffPatcher . patch ( sourceBytes , patchStream , output ) ; patchStream . close ( ) ; } else { ZipEntry outputEntry = new ZipEntry ( sourceEntry ) ; output . putNextEntry ( outputEntry ) ; output . write ( sourceBytes ) ; } } output . closeEntry ( ) ; } list . close ( ) ; } catch ( PatchException pe ) { IOException ioe = new IOException ( ) ; ioe . initCause ( pe ) ; throw ioe ; } finally { source . close ( ) ; patch . close ( ) ; output . close ( ) ; } }
Applies the differences in patch to source to create the target file.
Applies the differences in patch to source to create the target file .
// new Entry
 // changed Entry
 // unchanged Entry
 //nach jedem: output.putNextEntry() + output.write()
