content: package com.admin4j.framework.signature.core;
  
  import org.apache.commons.io.IOUtils;
  
  import javax.servlet.ReadListener;
  import javax.servlet.ServletInputStream;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletRequestWrapper;
  import java.io.*;
  
  public class CacheHttpServletRequestWrapper extends HttpServletRequestWrapper {
  
      /**
       * 缓存的内容
       */
      private final byte[] body;
  
      public CacheHttpServletRequestWrapper(HttpServletRequest request) throws IOException {
          super(request);
          body = IOUtils.toByteArray(request.getInputStream());
      }
  
      @Override
      public ServletInputStream getInputStream() {
          final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body);
          return new ServletInputStream() {
              @Override
              public boolean isFinished() {
                  return false;
              }
  
              @Override
              public boolean isReady() {
                  return false;
              }
  
              @Override
              public void setReadListener(ReadListener readListener) {
              }
  
              @Override
              public int read() {
                  return byteArrayInputStream.read();
              }
  
              @Override
              public int available() {
                  return body.length;
              }
          };
      }
  
      @Override
      public BufferedReader getReader() {
          return new BufferedReader(new InputStreamReader(this.getInputStream()));
      }
  
      public byte[] getBody() {
          return this.body;
      }
  }
  