title: MD5 Hash mismatch after Object Compression
body: <p>I am compressing a Serializable Object using following snippet:</p>
  
  <pre><code> private byte[] compressObject(Object obj) throws IOException {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      GZIPOutputStream gzipOut = new GZIPOutputStream(baos);
      ObjectOutputStream objectOut = new ObjectOutputStream(gzipOut);
      objectOut.writeObject(obj);     
      objectOut.close();
      byte[] bytes = baos.toByteArray();
  
      return bytes;       
  }
  </code></pre>
  
  <p>And decompressing the same object using following snippet:</p>
  
  <pre><code>private Object decompressObject(byte[] bytes) throws IOException,ClassNotFoundException {
      ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
      GZIPInputStream gzipIn = new GZIPInputStream(bais);
      ObjectInputStream objectIn = new ObjectInputStream(gzipIn);
      Object obj = objectIn.readObject();     
      objectIn.close();
  
      return obj;
  }
  </code></pre>
  
  <p>Before compressing the Object and after decompressing the Object, I calculate the MD5 Hash using following snippet:</p>
  
  <pre><code>public String getMD5Hash(Object obj) throws IOException, NoSuchAlgorithmException {
  
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      ObjectOutput out = new ObjectOutputStream(bos);   
      out.writeObject(obj);
      byte[] data = bos.toByteArray();                
      MessageDigest m = MessageDigest.getInstance("MD5");                     
      m.update(data,0,data.length);
      BigInteger i = new BigInteger(1,m.digest());
      return String.format("%1$032X", i);     
  }
  </code></pre>
  
  <p>But the MD5 Hash calculated before compression and after compression does not match. Kindly suggest how to get the Object as it is after decompression.</p>
  
  <p>Thanks.</p>