简体   繁体   中英

Jersey 1.17 download large files

I want to download large files from REST service, I have code:

@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

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

Hope it provide you the functionality you need.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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