diff --git a/src/main/groovy/net/gleske/jervis/tools/GZip.groovy b/src/main/groovy/net/gleske/jervis/tools/GZip.groovy index 5891bc7d..7cb1f884 100644 --- a/src/main/groovy/net/gleske/jervis/tools/GZip.groovy +++ b/src/main/groovy/net/gleske/jervis/tools/GZip.groovy @@ -84,6 +84,7 @@ assert response.responseCode == 201
import net.gleske.jervis.tools.GZip
import net.gleske.jervis.tools.SecurityIO
+import java.util.zip.GZIPInputStream
ByteArrayOutputStream compressed = new ByteArrayOutputStream()
// best speed compression
@@ -92,9 +93,17 @@ new GZip(compressed, 1).withCloseable {
it << ' world'
}
-// compressed data encoded as base64
-// to decompress you'll want to use SecurityIO.decodeBase64Bytes
+// COMPRESSED data encoded as base64
String data = SecurityIO.encodeBase64(compressed.toByteArray())
+
+// DECOMPRESS example
+ByteArrayOutputStream plain = new ByteArrayOutputStream()
+new ByteArrayInputStream(SecurityIO.decodeBase64Bytes(data)).withCloseable { is ->
+ new GZIPInputStream(is).withCloseable { gunzip ->
+ plain << gunzip
+ }
+}
+assert plain.toString() == 'hello world'
*/