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 as.stream.Lines
handler for incoming data. Since the same project is also using Spray.io, I attempted to use it's GzipDecompressor
on the HttpResponseBodyPart
bytes, but it threw an exception. See below:
def onBodyPartReceived(bodyPart: HttpResponseBodyPart) = {
if (state == CONTINUE) {
val decomp = new GzipDecompressor
val bytes = decomp.decompress( bodyPart.getBodyPartBytes )
onString(new String(bytes, charset))
}
state
}
The method above modifies the following (line 23): https://github.com/dispatch/reboot/blob/master/core/src/main/scala/stream/strings.scala#L23
It throws an exception! java.util.zip.ZipException: Not in GZIP format
For those wondering what GzipDecompressor looks like, here it is: https://github.com/spray/spray/blob/master/spray-httpx/src/main/scala/spray/httpx/encoding/Gzip.scala
I know that it is indeed a Gzipped stream. Any workarounds? Thanks!
Update
Playing around with the following:
val machine = new GZIPDecompressMachine
val bytes = machine.write( bodyPart.getBodyPartBytes )
onString(machine.stop().flatMap((a) => a).mkString)
The class GZIPDecompressMachine
comes from here: https://gist.github.com/841435/09921c8dcbb6b2ad01a3161589ed4fe68f256fbc
It's throwing an exception: java.io.EOFException: Unexpected end of ZLIB input stream
any ideas here?