我有一个返回ResponseEntity(InputStreamResource) 的方法。在此方法中,我根据文件名输入从文件中获取 InputStream,然后将 InputStreamResource 作为响应发送。
代码片段
InputStream inputStream = ...;
ResponseEntity<InputStreamResource> response = new ResponseEntity<InputStreamResource>(new InputStreamResource(inputStream), headers, HttpStatus.OK);
return response;
Run Code Online (Sandbox Code Playgroud)
这里我需要关闭 inputStream 对象吗?如果我这样做,我会得到
IllegalStateException:已关闭消息。我是否需要明确关闭它们或容器会照顾。