Skip to content

Instantly share code, notes, and snippets.

@rwoloszyn
Created April 7, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwoloszyn/f00e6af2bbc4e490fe369e3fc3bde6f8 to your computer and use it in GitHub Desktop.
Save rwoloszyn/f00e6af2bbc4e490fe369e3fc3bde6f8 to your computer and use it in GitHub Desktop.
Test Okio GzipSink
@Test
public void testGzipSource() throws IOException {
String original = "Some super super long string.Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string.";
ByteArrayOutputStream out = new ByteArrayOutputStream();
Sink sink = Okio.sink(out);
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
gzipSink.write(original.getBytes());
gzipSink.close();
out.close();
byte[] tmpData = out.toByteArray();
byte[] b = gunzip(tmpData);
System.out.println(new String(b));
Assert.assertEquals(original, new String(b));
}
/* Taken from test suit for Okio */
private byte[] gunzip(byte[] gzipped) throws IOException {
Buffer result = new Buffer();
GzipSource source = new GzipSource(Okio.source(new ByteArrayInputStream(gzipped)));
while (source.read(result, Integer.MAX_VALUE) != -1) {
}
return result.readByteArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment