package org.ambraproject.wombat.service.remote;

import org.apache.http.HttpEntity;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.entity.ContentType;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;

public class ReaderService extends AbstractRemoteService<Reader> {

  public ReaderService(HttpClientConnectionManager connectionManager) {
    super(connectionManager);
  }

  @Override
  public Reader open(HttpEntity entity) throws IOException {
    Charset charset = ContentType.getOrDefault(entity).getCharset();
    return new InputStreamReader(entity.getContent(), charset);
  }

}

@@ -38,24 +38,108 @@
 ce.remote;%0A%0A
+import com.google.common.base.Preconditions;%0Aimport org.apache.commons.io.Charsets;%0A
 import org.a
@@ -161,16 +161,16 @@
 Entity;%0A
-
 import o
@@ -260,16 +260,73 @@
 entType;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -504,16 +504,98 @@
 eader%3E %7B
+%0A  private static final Logger log = LoggerFactory.getLogger(ReaderService.class);
 %0A%0A  publ
@@ -695,16 +695,727 @@
 );%0A  %7D%0A%0A
+  /*%0A   * Default for converting the response's byte stream to characters.%0A   * Preferred over java.nio.charset.Charset.defaultCharset() to avoid an environmental dependency.%0A   */%0A  private static final Charset DEFAULT_CHARSET = Charsets.UTF_8;%0A%0A  private static Charset getCharsetOrDefault(HttpEntity entity) %7B%0A    Charset charset = null;%0A    ContentType contentType = ContentType.get(Preconditions.checkNotNull(entity));%0A    if (contentType != null) %7B%0A      charset = contentType.getCharset(); // may be null%0A    %7D%0A    if (charset == null) %7B%0A      log.warn(%22Charset not specified in response header; defaulting to %7B%7D%22, DEFAULT_CHARSET.name());%0A      charset = DEFAULT_CHARSET;%0A    %7D%0A    return charset;%0A  %7D%0A%0A
   @Overr
@@ -1501,29 +1501,24 @@
 arset = 
-ContentType.g
+getChars
 etOrDefa
@@ -1528,29 +1528,16 @@
 (entity)
-.getCharset()
 ;%0A    re

Improve default character encoding in ReaderService