Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
GZIP Test
import java.io.ByteArrayInputStream
import java.util.zip.GZIPOutputStream
import java.util.zip.GZIPInputStream
import java.io.ByteArrayOutputStream
val buffer = new Array[Byte](1024*4)
def gzip(bytes: Array[Byte]) = {
val byteIn = new ByteArrayInputStream(bytes)
val byteOut = new ByteArrayOutputStream()
val gzipOut = new GZIPOutputStream(byteOut)
var n = byteIn.read(buffer)
while (-1 != n) {
gzipOut.write(buffer, 0, n);
n = byteIn.read(buffer)
}
gzipOut.close()
byteOut.toByteArray()
}
def ungzip(bytes: Array[Byte]) = {
val byteIn = new ByteArrayInputStream(bytes)
val gzipIn = new GZIPInputStream(byteIn)
val byteOut = new ByteArrayOutputStream()
var n = gzipIn.read(buffer)
while (-1 != n) {
byteOut.write(buffer, 0, n);
n = gzipIn.read(buffer)
}
byteOut.toByteArray()
}
val bytes = ungzip(gzip("hi".getBytes()) ++ gzip("bye".getBytes()))
println(new String(bytes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.