code: private static InputStream bufferToTraceLog(InputStream input, String message, Logger log) {
          InputStream output;
          try {
              ByteArrayOutputStream buffer = new ByteArrayOutputStream();
              int read;
              byte[] data = new byte[16384];
              while ((read = input.read(data, 0, data.length)) != -1) {
                  buffer.write(data, 0, read);
              }
              buffer.flush();
              log.trace(message + "\n\n\n" + new String(buffer.toByteArray(), CHARSET_OUTPUT) + "\n\n\n");
              output = new ByteArrayInputStream(buffer.toByteArray());
          } catch (Exception e) {
              throw new RuntimeException("could not buffer stream", e);
          }
          return output;
      }
docs: Buffer a stream, flushing it to <code>log</code> and returning it as input
  
  @param input
  @param message
  @param log
  @return