Created
August 21, 2015 18:25
-
-
Save vovkab/b9c8ffa86d97e685d3cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private String decodeBody(Response response) throws IOException { | |
final ResponseBody body = response.body(); | |
if (body == null) return null; | |
if (isZipped(response)) { | |
return unzip(response.body()); | |
} else { | |
return body.string(); | |
} | |
} | |
private boolean isZipped(Response response) { | |
return "gzip".equalsIgnoreCase(response.header("Content-Encoding")); | |
} | |
private String unzip(ResponseBody body) { | |
try { | |
GzipSource responseBody = new GzipSource(body.source()); | |
return Okio.buffer(responseBody).readUtf8(); | |
} catch (IOException e) { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment