tomcat-embed-core 8.5.4 缺少 AbstractServletInputStream

AbstractServletInputStream missing on tomcat-embed-core 8.5.4

最近将一个 java 项目从 spring-boot 1.3.0 更新到 1.4.0,它使用 tomcat-embed-core 8.0.28 现在缺少 AbstractServletInputStream在使用 tomcat-embed-core 8.5.4 的最新版本 spring 引导上。这个class的alternative/replacement是什么?

这是旧代码块,希望对我的案例有所帮助:

public class MultiReadHttpServletRequest extends HttpServletRequestWrapper {
    ...
    public class CachedServletInputStream extends AbstractServletInputStream {
        private ByteArrayInputStream input;

        public CachedServletInputStream() {
            input = new ByteArrayInputStream(cachedBytes.toByteArray());
        }

        /**
        * Returns true. This stream is always ready.
        */
        @Override
        protected boolean doIsReady() throws IOException {
            return true;
        }

        /**
         * Reads the next set of bytes into the byte array.
         */
        @Override
        protected int doRead(boolean b, byte[] bytes, int i, int i1) throws IOException {
            return input.read(bytes, i, i1);
        }

       /**
        * Closes this stream. This does not affect any other streams that are dependent
        * on the cached content.
        */
        @Override
        protected void doClose() throws IOException {
            input.close();
        }
    }
}

您可以使用CoyoteInputStream instead of AbstractServletInputStream

我这样做了,似乎有效。

public class CachedServletInputStream extends ServletInputStream {
    private ByteArrayInputStream input;
    private boolean finished;

    public CachedServletInputStream() {
        input = new ByteArrayInputStream(cachedBytes.toByteArray());
    }

    @Override
    public int read() throws IOException {
        int b = input.read();
        finished = b == -1;
        return b;
    }

    @Override
    public boolean isFinished() {
        return finished;
    }

    @Override
    public boolean isReady() {
        return true;
    }

    @Override
    public void setReadListener(ReadListener readListener) {
    }
}