title: Decompress async-http-client gzipped HttpResponseBodyPart in Scala?
body: <p>Because Scala Dispatch 0.9.5 doesn't seem to have a default handler for decompressing GZIP streams, I'm attempting to modify it's <code>as.stream.Lines</code> handler for incoming data. Since the same project is also using Spray.io, I attempted to use it's <code>GzipDecompressor</code> on the <code>HttpResponseBodyPart</code> bytes, but it threw an exception. See below:</p>
  
  <pre><code>def onBodyPartReceived(bodyPart: HttpResponseBodyPart) = {
      if (state == CONTINUE) {
        val decomp = new GzipDecompressor
        val bytes = decomp.decompress( bodyPart.getBodyPartBytes )
        onString(new String(bytes, charset))
      }
      state
    }
  </code></pre>
  
  <p>The method above modifies the following (line 23): <a href="https://github.com/dispatch/reboot/blob/master/core/src/main/scala/stream/strings.scala#L23" rel="nofollow">https://github.com/dispatch/reboot/blob/master/core/src/main/scala/stream/strings.scala#L23</a></p>
  
  <p>It throws an exception! <code>java.util.zip.ZipException: Not in GZIP format</code> For those wondering what GzipDecompressor looks like, here it is: <a href="https://github.com/spray/spray/blob/master/spray-httpx/src/main/scala/spray/httpx/encoding/Gzip.scala" rel="nofollow">https://github.com/spray/spray/blob/master/spray-httpx/src/main/scala/spray/httpx/encoding/Gzip.scala</a></p>
  
  <p>I know that it is indeed a Gzipped stream. Any workarounds? Thanks!</p>
  
  <h2>Update</h2>
  
  <p>Playing around with the following:</p>
  
  <pre><code>  val machine = new GZIPDecompressMachine
    val bytes = machine.write( bodyPart.getBodyPartBytes )
    onString(machine.stop().flatMap((a) =&gt; a).mkString)
  </code></pre>
  
  <p>The class <code>GZIPDecompressMachine</code> comes from here: <a href="https://gist.github.com/841435/09921c8dcbb6b2ad01a3161589ed4fe68f256fbc" rel="nofollow">https://gist.github.com/841435/09921c8dcbb6b2ad01a3161589ed4fe68f256fbc</a></p>
  
  <p>It's throwing an exception: <code>java.io.EOFException: Unexpected end of ZLIB input stream</code> any ideas here?</p>