-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathHttpUtils.java
More file actions
36 lines (27 loc) · 1.18 KB
/
HttpUtils.java
File metadata and controls
36 lines (27 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package br.com.userede.erede;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
public class HttpUtils {
public static String parseResponse(HttpResponse response) throws IOException {
HttpEntity responseEntity = response.getEntity();
InputStream responseEntityContent = responseEntity.getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
responseEntityContent = new GZIPInputStream(responseEntityContent);
}
BufferedReader responseReader = new BufferedReader(
new InputStreamReader(responseEntityContent));
StringBuilder responseBuilder = new StringBuilder();
String line;
while ((line = responseReader.readLine()) != null) {
responseBuilder.append(line);
}
return responseBuilder.toString();
}
}