private void interceptResponseContent(HttpResponse response) {
    HttpEntity entity = response.getEntity();
    if (entity instanceof HttpEntityWrapper) {
      HttpEntityWrapper entityWrapper = (HttpEntityWrapper) entity;
      try {
        Field wrappedEntity = HttpEntityWrapper.class.getDeclaredField("wrappedEntity");
        wrappedEntity.setAccessible(true);
        entity = (HttpEntity) wrappedEntity.get(entityWrapper);
      } catch (Exception e) {
        // fail to record
      }
    }
    if (entity instanceof BasicHttpEntity) {
      BasicHttpEntity basicEntity = (BasicHttpEntity) entity;
      try {
        Field contentField = BasicHttpEntity.class.getDeclaredField("content");
        contentField.setAccessible(true);
        InputStream content = (InputStream) contentField.get(basicEntity);

        byte[] buffer = Util.readBytes(content);

        Robolectric.getFakeHttpLayer().addHttpResponseContent(buffer);
        contentField.set(basicEntity, new ByteArrayInputStream(buffer));
      } catch (Exception e) {
        // fail to record
      }
    }
  }
Esempio n. 2
0
 protected int findValueFor(String key) {
   String valueFor = attrData.getValueFor(key);
   if (valueFor == null) {
     // Maybe they have passed in the value directly, rather than the name.
     if (attrData.isValue(key)) {
       valueFor = key;
     } else {
       throw new RuntimeException("no value found for " + key);
     }
   }
   return Util.parseInt(valueFor);
 }