title: Why am I not getting my original string after compression and decompression?
body: <p>I am currently trying to use the <strong>java.util.zip.*</strong> package to perform lossless compression/Decompression. </p>
  
  <p>And I have used <strong>apache's</strong> jar to encode and decode the String used as an argument in Base64 charset.</p>
  
  <p>Following in my code with two static methods one each for compression and one for decompression.</p>
  
  <pre><code>import java.io.UnsupportedEncodingException;
  import java.nio.charset.Charset;
  import java.util.zip.*;
  
  import org.apache.commons.codec.binary.Base64;
  
  public class main {
  
      public String compress(String stringToCompress) throws UnsupportedEncodingException
      {       
          //System.out.println("String to Be Compressed :: " + stringToCompress);
          byte[] input = Base64.decodeBase64(stringToCompress);
  
          Deflater compressor = new Deflater();
          compressor.setInput(input);
          compressor.finish();
  
          byte[] output = new byte[100];
          compressor.deflate(output);
          return Base64.encodeBase64String(output);
      }
  
      public String decompressToString(String stringToDecompress) throws UnsupportedEncodingException, DataFormatException
      {   
          //System.out.println("String to be Decompressed :: " + stringToDecompress);
          byte[] input = Base64.decodeBase64(stringToDecompress);
  
          Inflater deCompressor = new Inflater();
          deCompressor.setInput(input,0,input.length);
  
          byte[] output = new byte[100];
          deCompressor.inflate(output);
          deCompressor.end();
  
          return Base64.encodeBase64String(output);
      }
  
  
      public static void main(String[] args) throws UnsupportedEncodingException, DataFormatException {
          main m = new main();
          String strToBeCompressed  = "jhjksdhgfkjdsfhkjhjvblkajnlkdfmvlksjfdovbjaiudhv adjv ajgvoig avigogauguivadfhijbjkla";
          String compressedString  = m.compress(strToBeCompressed) ;
          String deCompressedString = m.decompressToString(compressedString);
  
          System.out.println("Original :: " + strToBeCompressed);
          System.out.println("Compressed :: " + compressedString);
          System.out.println("decompressed :: " + deCompressedString);
      }
  }
  </code></pre>
  
  <p>Here is the output.</p>
  
  <pre><code>Original :: jhjksdhgfkjdsfhkjhjvblkajnlkdfmvlksjfdovbjaiudhv adjv ajgvoig avigogauguivadfhijbjkla
  Compressed :: eJwBPQDC/44Y5LHYYH5I3bH4ZI4Y725ZGo55ZHX5r5ZLI33aL242ornYb2nY72o4L6IoGr4oKIGroLor2nX4Yo245JXcvx/9AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
  decompressed :: jhjksdhgfkjdsfhkjhjvblkajnlkdfmvlksjfdovbjaiudhvadjvajgvoigavigogauguivadfhijbjklQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
  </code></pre>
  
  <p>If you see the output the original and decompressed string are not matching. I don't know why? Can any one tell me the reason.</p>