简体   繁体   English

Jersey 1.17下载大文件

[英]Jersey 1.17 download large files

I want to download large files from REST service, I have code: 我想从REST服务下载大文件,我有代码:

@GET
@Path("/laboDownloadAnyType")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response laboDownload() throws FileNotFoundException
{
    final String fileName = "SampleVideo_1280x720_50mb.mp4";
    final InputStream fileInStream = new FileInputStream(fileName);
    return Response.ok(fileInStream, MediaType.APPLICATION_OCTET_STREAM_TYPE)
      .header("Content-Disposition", "attachment; filename=\"" + fileName + "\"" ) //optional
      .build();
}

and when I'm using small files it works really great, but now I want to download large file (from 500MB to 3GB) I'm getting 当我使用小文件它真的很棒,但现在我想下载大文件(从500MB到3GB)我得到了

java.lang.OutOfMemoryError: Java heap space

How to solve this problem? 如何解决这个问题呢?

Use MappedByteBuffer instead of InputStream , you can check the implementation of MappedByteBuffer here Check this link 使用MappedByteBuffer而不是InputStream,你可以在这里查看 MappedByteBuffer的实现检查这个链接

Hope it provide you the functionality you need. 希望它为您提供所需的功能。

问题解决了:我不得不关闭Comunication Logging

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM