code: private static HttpEntity entityFromConnection(HttpURLConnection connection) {
          BasicHttpEntity entity = new BasicHttpEntity();
          InputStream inputStream;
          try {
              inputStream = connection.getInputStream();
          } catch (IOException ioe) {
              inputStream = connection.getErrorStream();
          }
          entity.setContent(inputStream);
          entity.setContentLength(connection.getContentLength());
          entity.setContentEncoding(connection.getContentEncoding());
          entity.setContentType(connection.getContentType());
          return entity;
      }
docs: Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}.
  @param connection
  @return an HttpEntity populated with data from <code>connection</code>.