1

如果response返回InputStreamResource什么时候关闭流

 2 years ago
source link: https://www.oschina.net/question/3913177_2323685
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如果response返回InputStreamResource什么时候关闭流

喀纳斯水怪 发布于 前天 13:45
阅读 145

如果我有一个如下的接口返回要下载的文件流,这个文件流什么时候关闭它?

@GetMapping("/{serviceName}/{fdId}")
    public ResponseEntity getFileInputStream() {

        InputStreamResource body = null;

        try {
            body = new InputStreamResource(minioService.getFileInputStream(serviceName, buildObjectName(dir, fdId)));
        } catch (Exception minioEx) {
          xxx
        }

        MultiValueMap headers = new HttpHeaders();
        headers.add("Content-Type", "application/octet-stream");
        return new ResponseEntity(body, headers, HttpStatus.OK);

如果主动先关闭流则客户端请求失败;如果不主动关闭流,那么InputStreamResource是什么时候关闭的流?谁触发的关闭?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK