Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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