'How to get both parts and InputStream from a request

I can't get the parts of a HTTP request and its InputStream at the same time. If I read the InputStream, then the part will be null. And I tried to save them, but if I get the parts, the InputStream can't be read.

public RepeatReadRequest(HttpServletRequest request) {
    super(request);
    try {
        parts = request.getParts();
    } catch (Exception e) {
    }
    try {
        byte[] tempBuffer = new byte[bufferSize];
        ServletInputStream inputStream = request.getInputStream();
        int len = inputStream.read(tempBuffer);
        if (len < 0) {
            len = 0;
        }
        buffer = Arrays.copyOf(tempBuffer, len);
    } catch (Exception e) {
        e.printStackTrace();
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source