title: Uncompress GZIPed HTTP Response in Java
body: <p>I'm trying to uncompress a GZIPed HTTP Response by using <code>GZIPInputStream</code>. However I always have the same exception when I try to read the stream : <code>java.util.zip.ZipException: invalid bit length repeat</code></p>
  
  <p>My HTTP Request Header:</p>
  
  <pre><code>GET www.myurl.com HTTP/1.0\r\n
  User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2) Gecko/20100115 Firefox/3.6\r\n
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
  Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3\r\n
  Accept-Encoding: gzip,deflate\r\n
  Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7\r\n
  Keep-Alive: 115\r\n
  Connection: keep-alive\r\n
  X-Requested-With: XMLHttpRequest\r\n
  Cookie: Some Cookies\r\n\r\n
  </code></pre>
  
  <p>At the end of the HTTP Response header, I get <code>path=/Content-Encoding: gzip</code>, followed by the gziped response.</p>
  
  <p>I tried 2 similars codes to uncompress :</p>
  
  <p>UPDATE : In the following codes, <code>tBytes = (the string after 'path=/Content-Encoding: gzip').getBytes ();</code></p>
  
  <pre><code>GZIPInputStream  gzip = new GZIPInputStream (new ByteArrayInputStream (tBytes));
  
  StringBuffer  szBuffer = new StringBuffer ();
  
  byte  tByte [] = new byte [1024];
  
  while (true)
  {
      int  iLength = gzip.read (tByte, 0, 1024); // &lt;-- Error comes here
  
      if (iLength &lt; 0)
          break;
  
      szBuffer.append (new String (tByte, 0, iLength));
  }
  </code></pre>
  
  <p>And this one that I get on this forum :</p>
  
  <pre><code>InputStream     gzipStream = new GZIPInputStream   (new ByteArrayInputStream (tBytes));
  Reader          decoder    = new InputStreamReader (gzipStream, "UTF-8");//&lt;- I tried ISO-8859-1 and get the same exception
  BufferedReader  buffered   = new BufferedReader    (decoder);
  </code></pre>
  
  <p>I guess this is an encoding error.</p>
  
  <p>Best regards,</p>
  
  <p>bill0ute</p>