Created
April 7, 2017 12:57
-
-
Save rwoloszyn/f00e6af2bbc4e490fe369e3fc3bde6f8 to your computer and use it in GitHub Desktop.
Test Okio GzipSink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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