Java jersey(web服务):StreamingOutput的优势和创建下载API的最佳方式

Java jersey(web服务):StreamingOutput的优势和创建下载API的最佳方式,java,rest,jersey,streaming,download,Java,Rest,Jersey,Streaming,Download,我使用此方法为我的RESTweb服务创建了一个API,用于使用jerseyJAX-RS下载文件: public Response returnFile(String filePath,String fileName,MediaType type) throws IOException { File file = new File(filePath); String[] filePart = filePath.split("\\."); String fileEnd = f

我使用此方法为我的
REST
web服务创建了一个API,用于使用jersey
JAX-RS
下载文件:

public Response returnFile(String filePath,String fileName,MediaType type) throws IOException {
    File file = new File(filePath);
    String[] filePart = filePath.split("\\.");
    String fileEnd = filePart[filePart.length - 1];
    return Response.ok(file, type)
        .header("Content-Disposition","attachment; filename=\"" 
            + URLEncoder.encode(fileName + "." + fileEnd,"UTF-8") + "\"" ) 
            .build(); 
}
但有人告诉我这可能会有性能问题,并导致
OutOfMemory
异常

所以我最近搜索了创建这样的API,发现大多数示例都使用了
StreamingOutput


那么使用
流化输出的好处是什么呢?在我的方法中使用它而不是在
文件中使用它是否更好?如果有人说创建这类API(用于下载文件的API)的最佳方法,我将不胜感激。

是的,它更节省内存。阅读本文了解更多信息:

是的,它更节省内存。阅读这篇文章了解更多信息:

更具体地告诉你的答案,这个问题太老了,我很久以前就找到了答案,但我很感谢你花时间在这个问题上,更具体地告诉你的答案,这个问题太老了,我很久以前就找到了答案,但我很感谢你花时间在这个问题上