Beispiel #1
0
 /**
  * Content stream may need to be read. However, we should always close the http stream.
  *
  * @throws IOException
  */
 public static byte[] closeClientButKeepContentStream(PayloadEnclosing response) {
   byte[] returnVal = toByteArrayOrNull(response);
   if (returnVal != null && !response.getPayload().isRepeatable()) {
     Payload newPayload = Payloads.newByteArrayPayload(returnVal);
     MutableContentMetadata fromMd = response.getPayload().getContentMetadata();
     MutableContentMetadata toMd = newPayload.getContentMetadata();
     copy(fromMd, toMd);
     response.setPayload(newPayload);
   }
   return returnVal;
 }
Beispiel #2
0
 public static byte[] toByteArrayOrNull(PayloadEnclosing response) {
   if (response.getPayload() != null) {
     InputStream input = response.getPayload().getInput();
     try {
       return toByteArray(input);
     } catch (IOException e) {
       propagate(e);
     } finally {
       closeQuietly(input);
     }
   }
   return null;
 }