20
20
import com .google .common .collect .ImmutableList ;
21
21
import com .google .common .collect .ImmutableMap ;
22
22
import com .google .common .collect .Maps ;
23
- import com .google .common .io .CharStreams ;
24
23
import com .google .common .net .HttpHeaders ;
25
24
import com .google .common .primitives .Longs ;
26
25
import com .palantir .conjure .java .api .errors .QosException ;
43
42
import java .io .ByteArrayInputStream ;
44
43
import java .io .IOException ;
45
44
import java .io .InputStream ;
46
- import java .io .InputStreamReader ;
47
- import java .io .Reader ;
48
45
import java .net .MalformedURLException ;
49
46
import java .net .URL ;
50
47
import java .nio .charset .StandardCharsets ;
@@ -71,6 +68,8 @@ final class EndpointErrorDecoder<T> {
71
68
private static final Encoding JSON_ENCODING = Encodings .json ();
72
69
private static final Deserializer <NamedError > NAMED_ERROR_DESERIALIZER =
73
70
JSON_ENCODING .deserializer (new TypeMarker <>() {});
71
+ private static final Deserializer <SerializableError > SERIALIZABLE_ERROR_DESERIALIZER =
72
+ JSON_ENCODING .deserializer (new TypeMarker <>() {});
74
73
private final Map <String , Encoding .Deserializer <? extends T >> errorNameToJsonDeserializerMap ;
75
74
76
75
EndpointErrorDecoder (Map <String , TypeMarker <? extends T >> errorNameToTypeMap ) {
@@ -187,15 +186,14 @@ private T decodeInternal(Response response) {
187
186
}
188
187
189
188
private static RemoteException createRemoteException (byte [] body , int code ) throws IOException {
190
- SerializableError serializableError = JSON_ENCODING
191
- .deserializer (new TypeMarker <SerializableError >() {})
192
- .deserialize (new ByteArrayInputStream (body ));
189
+ SerializableError serializableError =
190
+ SERIALIZABLE_ERROR_DESERIALIZER .deserialize (new ByteArrayInputStream (body ));
193
191
return new RemoteException (serializableError , code );
194
192
}
195
193
196
194
private static byte [] toByteArray (InputStream body ) throws IOException {
197
- try (Reader reader = new InputStreamReader ( body , StandardCharsets . UTF_8 ) ) {
198
- return CharStreams . toString ( reader ). getBytes ( StandardCharsets . UTF_8 );
195
+ try (body ) {
196
+ return body . readAllBytes ( );
199
197
}
200
198
}
201
199
0 commit comments