Skip to content

Commit

Permalink
Update GZip example in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
samrocketman committed Oct 3, 2023
1 parent 1aa7682 commit 237a59e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/groovy/net/gleske/jervis/tools/GZip.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ assert response.responseCode == 201
<pre><code>
import net.gleske.jervis.tools.GZip
import net.gleske.jervis.tools.SecurityIO
import java.util.zip.GZIPInputStream
ByteArrayOutputStream compressed = new ByteArrayOutputStream()
// best speed compression
Expand All @@ -92,9 +93,17 @@ new GZip(compressed, 1).withCloseable {
it &lt;&lt; ' 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 -&gt;
new GZIPInputStream(is).withCloseable { gunzip -&gt;
plain &lt;&lt; gunzip
}
}
assert plain.toString() == 'hello world'
</code></pre>
*/

Expand Down

0 comments on commit 237a59e

Please sign in to comment.