【问题标题】:How to handle IO streams in Spring MVC如何在 Spring MVC 中处理 IO 流
【发布时间】:2018-07-17 12:27:44
【问题描述】:

我有一个返回 ResponseEntity(InputStreamResource) 的方法。在这种方法中,我根据文件名输入从文件中获取 InputStream,然后将 InputStreamResource 作为响应发送。

代码 sn-p

InputStream inputStream = ...;    
ResponseEntity<InputStreamResource> response = new ResponseEntity<InputStreamResource>(new InputStreamResource(inputStream), headers, HttpStatus.OK);
return response;

这里需要关闭 inputStream 对象吗?如果我这样做,我会得到 ​​p>

IllegalStateException:关闭消息。我是否需要明确关闭它们或容器会小心。

【问题讨论】:

    标签: spring-mvc inputstream


    【解决方案1】:

    处理这个的底层类是ResourceHttpMessageConverter,它关闭底层输入流,从here可以看出

    【讨论】:

      猜你喜欢
      • 2011-01-05
      • 2012-12-02
      • 2012-08-02
      • 2012-05-07
      • 1970-01-01
      • 1970-01-01
      • 2013-04-24
      • 2010-11-12
      • 1970-01-01
      相关资源
      最近更新 更多