-
Notifications
You must be signed in to change notification settings - Fork 52
/
SerializableHttpResponse.java
36 lines (30 loc) · 1.08 KB
/
SerializableHttpResponse.java
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 io.odpf.firehose.sink.http;
import org.apache.http.HttpResponse;
import org.apache.logging.log4j.util.Strings;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;
public class SerializableHttpResponse implements Serializable {
private HttpResponse httpResponse;
public SerializableHttpResponse(HttpResponse httpResponse) {
this.httpResponse = httpResponse;
}
@Override
public String toString() {
InputStream inputStream = null;
try {
inputStream = httpResponse.getEntity().getContent();
} catch (IOException e) {
e.printStackTrace();
}
return Strings.join(readContent(inputStream), '\n');
}
private List<String> readContent(InputStream inputStream) {
return new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines().collect(Collectors.toList());
}
}