diff --git a/dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/EndpointErrorDecoder.java b/dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/EndpointErrorDecoder.java index e3afa4f67..429a64c87 100644 --- a/dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/EndpointErrorDecoder.java +++ b/dialogue-serde/src/main/java/com/palantir/conjure/java/dialogue/serde/EndpointErrorDecoder.java @@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import com.google.common.io.CharStreams; import com.google.common.net.HttpHeaders; import com.google.common.primitives.Longs; import com.palantir.conjure.java.api.errors.QosException; @@ -43,8 +42,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -71,6 +68,8 @@ final class EndpointErrorDecoder { private static final Encoding JSON_ENCODING = Encodings.json(); private static final Deserializer NAMED_ERROR_DESERIALIZER = JSON_ENCODING.deserializer(new TypeMarker<>() {}); + private static final Deserializer SERIALIZABLE_ERROR_DESERIALIZER = + JSON_ENCODING.deserializer(new TypeMarker<>() {}); private final Map> errorNameToJsonDeserializerMap; EndpointErrorDecoder(Map> errorNameToTypeMap) { @@ -187,15 +186,14 @@ private T decodeInternal(Response response) { } private static RemoteException createRemoteException(byte[] body, int code) throws IOException { - SerializableError serializableError = JSON_ENCODING - .deserializer(new TypeMarker() {}) - .deserialize(new ByteArrayInputStream(body)); + SerializableError serializableError = + SERIALIZABLE_ERROR_DESERIALIZER.deserialize(new ByteArrayInputStream(body)); return new RemoteException(serializableError, code); } private static byte[] toByteArray(InputStream body) throws IOException { - try (Reader reader = new InputStreamReader(body, StandardCharsets.UTF_8)) { - return CharStreams.toString(reader).getBytes(StandardCharsets.UTF_8); + try (body) { + return body.readAllBytes(); } }