title: Compressing a string using GZIPOutputStream
body: <p>I want to zip my string values. These string values should be same as <code>.net</code> zipped strings.</p>
  <p>I wrote <em>Decompress</em> method and when I send a <code>.net</code> zipped string to it, it works correctly. But the <em>Compress</em> method does not work correctly.</p>
  <pre class="lang-java prettyprint-override"><code>public static String Decompress(String zipText) throws IOException {
      int size = 0;
      byte[] gzipBuff = Base64.decode(zipText);
  
      ByteArrayInputStream memstream = new ByteArrayInputStream(gzipBuff, 4,
              gzipBuff.length - 4);
      GZIPInputStream gzin = new GZIPInputStream(memstream);
  
      final int buffSize = 8192;
      byte[] tempBuffer = new byte[buffSize];
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      while ((size = gzin.read(tempBuffer, 0, buffSize)) != -1) {
          baos.write(tempBuffer, 0, size);
      }
      byte[] buffer = baos.toByteArray();
      baos.close();
  
      return new String(buffer, &quot;UTF-8&quot;);
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>public static String Compress(String text) throws IOException {
      byte[] gzipBuff = EncodingUtils.getBytes(text, &quot;UTF-8&quot;);
  
      ByteArrayOutputStream bs = new ByteArrayOutputStream();
      GZIPOutputStream gzin = new GZIPOutputStream(bs);
  
      gzin.write(gzipBuff);
      gzin.finish();
      bs.close();
  
      byte[] buffer = bs.toByteArray();
      gzin.close();
  
      return Base64.encode(buffer);
  }
  </code></pre>
  <p>For example when I send <strong>&quot;BQAAAB+LCAAAAAAABADtvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee++997o7nU4n99//P1xmZAFs9s5K2smeIYCqyB8/fnwfPyLmeVlW/w+GphA2BQAAAA==&quot;</strong> to <em>Decompress</em> method It returns the string &quot;Hello&quot;, but when I send <strong>&quot;Hello&quot;</strong> to <em>Compress</em> method It returns <strong>&quot;H4sIAAAAAAAAAMtIzcnJBwCGphA2BQAAAA==&quot;</strong>.</p>
  <p>What is the problem in <em>Compress</em> method????</p>