src/main/java/at/spardat/xma/xdelta/JarDelta.java
public void computeDelta(ZipFile source, ZipFile target, ZipOutputStream output) throws IOException {
        try {
            ByteArrayOutputStream listBytes = new ByteArrayOutputStream();
            PrintWriter list = new PrintWriter(new OutputStreamWriter(listBytes));
    		for(Enumeration enumer=target.entries();enumer.hasMoreElements();) {
    			ZipEntry targetEntry = (ZipEntry)enumer.nextElement();
                ZipEntry sourceEntry = source.getEntry(targetEntry.getName());
                list.println(targetEntry.getName());

                if(targetEntry.isDirectory()) {
                    if(sourceEntry==null) {
                        ZipEntry outputEntry = new ZipEntry(targetEntry);
                        output.putNextEntry(outputEntry);
                    }
                    continue;
                }

    			int targetSize = (int)targetEntry.getSize();
    			byte[] targetBytes = new byte[targetSize];
    			InputStream targetStream = target.getInputStream(targetEntry);
    			for(int erg=targetStream.read(targetBytes);erg<targetBytes.length;erg+=targetStream.read(targetBytes,erg,targetBytes.length-erg));
                targetStream.close();
                int chunk = Delta.DEFAULT_CHUNK_SIZE;
    			if(sourceEntry==null
                        || sourceEntry.getSize() <= chunk
                        || targetEntry.getSize() <= chunk) {  // new Entry od. alter Eintrag od. neuer Eintrag leer
    				ZipEntry outputEntry = new ZipEntry(targetEntry);
    				output.putNextEntry(outputEntry);
    				output.write(targetBytes);
    			} else {
    				int sourceSize = (int)sourceEntry.getSize();
    				byte[] sourceBytes = new byte[sourceSize];
    				InputStream sourceStream = source.getInputStream(sourceEntry);
    				for(int erg=sourceStream.read(sourceBytes);erg<sourceBytes.length;erg+=sourceStream.read(sourceBytes,erg,sourceBytes.length-erg));
    				sourceStream.close();
                    if(!equal(sourceBytes,targetBytes)) {
        				ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                        DiffWriter diffWriter = new GDiffWriter(new DataOutputStream(outputStream));
        				Delta d = new Delta();
        				d.compute(sourceBytes,target.getInputStream(targetEntry),diffWriter);
                        diffWriter.close();

        				ZipEntry outputEntry = new ZipEntry(targetEntry.getName()+".gdiff");
                        outputEntry.setTime(targetEntry.getTime());
        				output.putNextEntry(outputEntry);
        				output.write(outputStream.toByteArray());
                    }
    			}
    		}
            list.close();
            ZipEntry listEntry = new ZipEntry("META-INF/file.list");
            output.putNextEntry(listEntry);
            output.write(listBytes.toByteArray());
        } finally {
            source.close();
            target.close();
            output.close();
        }
	}
/**
     * Computes the binary differences of two zip files. For all files contained in source and target which
     * are not equal, the binary difference is caluclated by using
     * {@link com.nothome.delta.Delta#computeDelta(com.nothome.delta.SeekableSource, InputStream, int, DiffWriter)}.
     * If the files are equal, nothing is written to the output for them.
     * Files contained only in target and files to small for {@link com.nothome.delta.Delta} are copied to output.
     * Files contained only in source are ignored.
     * At last a list of all files contained in target is written to <code>META-INF/file.list</code> in output.
     *
     * @param source the original zip file
     * @param target a modification of the original zip file
     * @param output the zip file where the patches have to be written to
     * @throws IOException if an error occures reading or writing any entry in a zip file
     */
Computes the binary differences of two zip files. For all files contained in source and target which
are not equal, the binary difference is caluclated by using
com.nothome.delta.Delta#computeDelta(com.nothome.delta.SeekableSource, InputStream, int, DiffWriter).
If the files are equal, nothing is written to the output for them.
Files contained only in target and files to small for  com.nothome.delta.Delta are copied to output.
Files contained only in source are ignored.
At last a list of all files contained in target is written to META-INF/file.list in output.

@param source the original zip file
@param target a modification of the original zip file
@param output the zip file where the patches have to be written to
@throws IOException if an error occures reading or writing any entry in a zip file
Computes the binary differences of two zip files . For all files contained in source and target which are not equal the binary difference is caluclated by using com . nothome . delta . Delta#computeDelta ( com . nothome . delta . SeekableSource InputStream int DiffWriter ) . If the files are equal nothing is written to the output for them . Files contained only in target and files to small for com . nothome . delta . Delta are copied to output . Files contained only in source are ignored . At last a list of all files contained in target is written to META - INF / file . list in output . @param source the original zip file @param target a modification of the original zip file @param output the zip file where the patches have to be written to @throws IOException if an error occures reading or writing any entry in a zip file
public void computeDelta(ZipFile source, ZipFile target, ZipOutputStream output) throws IOException {
        try {
            ByteArrayOutputStream listBytes = new ByteArrayOutputStream();
            PrintWriter list = new PrintWriter(new OutputStreamWriter(listBytes));
    		for(Enumeration enumer=target.entries();enumer.hasMoreElements();) {
    			ZipEntry targetEntry = (ZipEntry)enumer.nextElement();
                ZipEntry sourceEntry = source.getEntry(targetEntry.getName());
                list.println(targetEntry.getName());
                if(targetEntry.isDirectory()) {
                    if(sourceEntry==null) {
                        ZipEntry outputEntry = new ZipEntry(targetEntry);
                        output.putNextEntry(outputEntry);
                    }
                    continue;
                }
    			int targetSize = (int)targetEntry.getSize();
    			byte[] targetBytes = new byte[targetSize];
    			InputStream targetStream = target.getInputStream(targetEntry);
    			for(int erg=targetStream.read(targetBytes);erg<targetBytes.length;erg+=targetStream.read(targetBytes,erg,targetBytes.length-erg));
                targetStream.close();
                int chunk = Delta.DEFAULT_CHUNK_SIZE;
    			if(sourceEntry==null
                        || sourceEntry.getSize() <= chunk
                        || targetEntry.getSize() <= chunk) {  
    				ZipEntry outputEntry = new ZipEntry(targetEntry);
    				output.putNextEntry(outputEntry);
    				output.write(targetBytes);
    			} else {
    				int sourceSize = (int)sourceEntry.getSize();
    				byte[] sourceBytes = new byte[sourceSize];
    				InputStream sourceStream = source.getInputStream(sourceEntry);
    				for(int erg=sourceStream.read(sourceBytes);erg<sourceBytes.length;erg+=sourceStream.read(sourceBytes,erg,sourceBytes.length-erg));
    				sourceStream.close();
                    if(!equal(sourceBytes,targetBytes)) {
        				ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                        DiffWriter diffWriter = new GDiffWriter(new DataOutputStream(outputStream));
        				Delta d = new Delta();
        				d.compute(sourceBytes,target.getInputStream(targetEntry),diffWriter);
                        diffWriter.close();
        				ZipEntry outputEntry = new ZipEntry(targetEntry.getName()+".gdiff");
                        outputEntry.setTime(targetEntry.getTime());
        				output.putNextEntry(outputEntry);
        				output.write(outputStream.toByteArray());
                    }
    			}
    		}
            list.close();
            ZipEntry listEntry = new ZipEntry("META-INF/file.list");
            output.putNextEntry(listEntry);
            output.write(listBytes.toByteArray());
        } finally {
            source.close();
            target.close();
            output.close();
        }
	}
public void computeDelta ( ZipFile source , ZipFile target , ZipOutputStream output ) throws IOException { try { ByteArrayOutputStream listBytes = new ByteArrayOutputStream ( ) ; PrintWriter list = new PrintWriter ( new OutputStreamWriter ( listBytes ) ) ; for ( Enumeration enumer = target . entries ( ) ; enumer . hasMoreElements ( ) ; ) { ZipEntry targetEntry = ( ZipEntry ) enumer . nextElement ( ) ; ZipEntry sourceEntry = source . getEntry ( targetEntry . getName ( ) ) ; list . println ( targetEntry . getName ( ) ) ; if ( targetEntry . isDirectory ( ) ) { if ( sourceEntry == null ) { ZipEntry outputEntry = new ZipEntry ( targetEntry ) ; output . putNextEntry ( outputEntry ) ; } continue ; } int targetSize = ( int ) targetEntry . getSize ( ) ; byte [ ] targetBytes = new byte [ targetSize ] ; InputStream targetStream = target . getInputStream ( targetEntry ) ; for ( int erg = targetStream . read ( targetBytes ) ; erg < targetBytes . length ; erg += targetStream . read ( targetBytes , erg , targetBytes . length - erg ) ) ; targetStream . close ( ) ; int chunk = Delta . DEFAULT_CHUNK_SIZE ; if ( sourceEntry == null || sourceEntry . getSize ( ) <= chunk || targetEntry . getSize ( ) <= chunk ) { ZipEntry outputEntry = new ZipEntry ( targetEntry ) ; output . putNextEntry ( outputEntry ) ; output . write ( targetBytes ) ; } else { int sourceSize = ( int ) sourceEntry . getSize ( ) ; byte [ ] sourceBytes = new byte [ sourceSize ] ; InputStream sourceStream = source . getInputStream ( sourceEntry ) ; for ( int erg = sourceStream . read ( sourceBytes ) ; erg < sourceBytes . length ; erg += sourceStream . read ( sourceBytes , erg , sourceBytes . length - erg ) ) ; sourceStream . close ( ) ; if ( ! equal ( sourceBytes , targetBytes ) ) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; DiffWriter diffWriter = new GDiffWriter ( new DataOutputStream ( outputStream ) ) ; Delta d = new Delta ( ) ; d . compute ( sourceBytes , target . getInputStream ( targetEntry ) , diffWriter ) ; diffWriter . close ( ) ; ZipEntry outputEntry = new ZipEntry ( targetEntry . getName ( ) + ".gdiff" ) ; outputEntry . setTime ( targetEntry . getTime ( ) ) ; output . putNextEntry ( outputEntry ) ; output . write ( outputStream . toByteArray ( ) ) ; } } } list . close ( ) ; ZipEntry listEntry = new ZipEntry ( "META-INF/file.list" ) ; output . putNextEntry ( listEntry ) ; output . write ( listBytes . toByteArray ( ) ) ; } finally { source . close ( ) ; target . close ( ) ; output . close ( ) ; } }
Computes the binary differences of two zip files.
Computes the binary differences of two zip files .
// new Entry od. alter Eintrag od. neuer Eintrag leer
