java的outputstream_java输入流

2022-09-27 14:49:04 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

我有这个InputStream:

InputStream inputStream = new ByteArrayInputStream(myString.getBytes(StandardCharsets.UTF_8));

如何将其转换为ServletInputStream?

我努力了:

ServletInputStream servletInputStream = (ServletInputStream) inputStream;

但不起作用。

编辑:

我的方法是这样的:

private static class LowerCaseRequest extends HttpServletRequestWrapper {

public LowerCaseRequest(final HttpServletRequest request) throws IOException, ServletException {

super(request);

}

@Override

public ServletInputStream getInputStream() throws IOException {

ServletInputStream servletInputStream;

StringBuilder jb = new StringBuilder();

String line;

String toLowerCase = “”;

BufferedReader reader = new BufferedReader(new InputStreamReader(super.getInputStream()));

while ((line = reader.readLine()) != null) {

toLowerCase = jb.append(line).toString().toLowerCase();

}

InputStream inputStream = new ByteArrayInputStream(toLowerCase.getBytes(StandardCharsets.UTF_8));

servletInputStream = (ServletInputStream) inputStream;

return servletInputStream;

}

}

我正在尝试将所有请求都转换为小写。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/193279.html原文链接:https://javaforall.cn

0 人点赞