开发者

Transform ServletInputStream to String

I am trying to get the bo开发者_StackOverflow社区dy of a HttpServletRequest in a String. What's the best elegant way to do so?


Using Apache Commons IO:

String requestStr = IOUtils.toString(request.getInputStream());


Other way, using Guava:

ByteSource.wrap(ByteStreams.toByteArray(request.getInputStream()))
    .asCharSource(Charsets.UTF_8).read()

See also:

  • http://www.baeldung.com/java-convert-inputstream-to-reader
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜