MD5 being returned is the same even after digesting the files - Java
<p>I wrote the following <code>Java</code> method to read all the entries of a <code>ZipInputStream</code> file and process its <code>MD5</code> based on <strong>FILE CONTENT ONLY</strong>. Inside my class <code>Tczip</code> I have:</p>

<pre><code> public String digest( ZipInputStream entry ) throws IOException{

            byte[] digest = null;
            MessageDigest md5 = null;
            String mdEnc = "";
            ZipEntry current;

            try {
                md5 = MessageDigest.getInstance( "MD5" );
                if( entry != null ) {
                    while(( current = entry.getNextEntry() ) != null ) {
                        if( current.isDirectory() ) {
                            digest = this.encodeUTF8( current.getName() );
                            md5.update( digest );
                        }
                        else{
                            int size = ( int )current.getSize();
                            if(size &gt; 0){
                                digest = new byte[ size ];
                                entry.read( digest, 0, size );
                                md5.update( digest );
                            }
                        }
                    }
                    digest = md5.digest();
                    mdEnc = new BigInteger( 1, md5.digest() ).toString( 16 );
                    entry.close();
                }
            }
            catch ( NoSuchAlgorithmException e ) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (IllegalArgumentException ex){
                System.out.println("There is an illegal encoding.");
                //
                // The fix for Korean/Chinese/Japanese encodings goes here
                //
                Charset encoding = Charset.forName("utf-8");
                ZipInputStream zipinputstream = 
                        new ZipInputStream(new FileInputStream( this.filename ), encoding);
                digest = new byte[ 1024 ];
                current = zipinputstream.getNextEntry();
                while (current != null) { //for each entry to be extracted
                    String entryName = current.getName();
                    System.out.println("Processing: " + entryName);
                    int n;
                    FileOutputStream fileoutputstream = 
                            new FileOutputStream( this.filename );

                    while (( n = zipinputstream.read( digest, 0, 1024 )) &gt; -1) {
                        fileoutputstream.write(digest, 0, n);
                    }

                    fileoutputstream.close(); 
                    zipinputstream.closeEntry();
                    current = zipinputstream.getNextEntry();
                }//while
                zipinputstream.close();
            }
            return mdEnc;
        }

        public byte[] encodeUTF8( String name ) {
            final Charset UTF8_CHARSET = Charset.forName( "UTF-8" );
            return name.getBytes( UTF8_CHARSET );
        }
</code></pre>

<p>Then the program would go over a root directory (aka <code>C:\workspace\path\to\source\code</code> ), iterating over all the directories, looking for <code>.zip</code> files to be processed. These files go into <code>File[] files</code>:</p>

<pre><code>public void showFiles( File[] files ){
        for( File file : files ){
            if( file.isDirectory() ) {
                showFiles( file.listFiles( this.filter ) );
            }
            else {
                try {
                    String path = file.getCanonicalPath();
                    String relative = path.replace("tc10.0.0.2012080100_A", "tc10.0.0.2012080600_C" );
                    File b = new File(relative);
                    if( b.exists() ) {
                        System.out.println( "Processing :" + file.getName() );
                        this.zip_a = new Tczip( path );
                        this.zip_b = new Tczip( relative );
                        String md5_a = this.zip_a.digest();
                        String md5_b = this.zip_b.digest();
                        System.out.println("MD5 A: " + md5_a);
                        System.out.println("MD5 B: " + md5_b);

                        if( md5_a.equals( md5_b )){
                            System.out.println( "They Match" );
                        }
                        else {
                            System.out.println( "They don't Match" );
                        }
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
</code></pre>

<p>So I wanted to process the <code>MD5</code> of all those zip files, and compare if they do match: <strong>TWO EQUAL(IN CONTENT) ZIP FILES ARE EXPECTED TO HAVE THE SAME MD5</strong>. If the file content is not the same, then the <code>MD5</code> would be different.
However, when I execute the program, I have:</p>

<pre><code>Processing :web.zip
MD5 A: d41d8cd98f00b204e9800998ecf8427e
MD5 B: d41d8cd98f00b204e9800998ecf8427e
They Match
Processing :weldmgmt_icons.zip
MD5 A: d41d8cd98f00b204e9800998ecf8427e
MD5 B: d41d8cd98f00b204e9800998ecf8427e
They Match
Processing :weldmgmt_install.zip
MD5 A: d41d8cd98f00b204e9800998ecf8427e
MD5 B: d41d8cd98f00b204e9800998ecf8427e
They Match
Processing :weldmgmt_template.zip
MD5 A: d41d8cd98f00b204e9800998ecf8427e
MD5 B: d41d8cd98f00b204e9800998ecf8427e
They Match
</code></pre>

<p>Why do they same the same <code>MD5</code>? I expect two files to have the same <code>MD5</code>, but not all of them. Any suggestions? What am I doing wrong?</p>
