Exemplo n.º 1
0
  /** Reads the contents of HttpEntity into a byte[]. */
  private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError {
    PoolingByteArrayOutputStream bytes =
        new PoolingByteArrayOutputStream(mPool, (int) entity.getContentLength());
    byte[] buffer = null;
    try {
      InputStream in = entity.getContent();
      Header contentEncoding = entity.getContentEncoding();
      if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
        in = new GZIPInputStream(in);
      }

      if (in == null) {
        throw new ServerError();
      }
      buffer = mPool.getBuf(1024);
      int count;
      while ((count = in.read(buffer)) != -1) {
        bytes.write(buffer, 0, count);
      }
      return bytes.toByteArray();
    } finally {
      try {
        // Close the InputStream and release the resources by "consuming the content".
        entity.consumeContent();
      } catch (IOException e) {
        // This can happen if there was an exception above that left the entity in
        // an invalid state.
        VolleyLog.v("Error occured when calling consumingContent");
      }
      mPool.returnBuf(buffer);
      bytes.close();
    }
  }
Exemplo n.º 2
0
 protected void logError(String what, String url, long start) {
   long now = SystemClock.elapsedRealtime();
   VolleyLog.v("HTTP ERROR(%s) %d ms to fetch %s", what, (now - start), url);
 }