我们如何使用Java8将ByteArrayInputStream转换为ServletInputStream?

时间:2019-12-26 11:04:14

标签: java-8

如何使用Java8将ByteArrayInputStream转换为ServletInputStream?

@Override
public ServletInputStream getInputStream() throws IOException {
    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
    ServletInputStream servletInputStream = new ServletInputStream() {
        public int read() throws IOException {
            return byteArrayInputStream.read();
        }

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

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

        @Override
        public void setReadListener(ReadListener listener) {
            // No implementation
        }
    };
    return servletInputStream;
}

0 个答案:

没有答案