簡體   English   中英

Jersey 1.17下載大文件

[英]Jersey 1.17 download large files

我想從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();
}

當我使用小文件它真的很棒,但現在我想下載大文件(從500MB到3GB)我得到了

java.lang.OutOfMemoryError: Java heap space

如何解決這個問題呢?

使用MappedByteBuffer而不是InputStream,你可以在這里查看 MappedByteBuffer的實現檢查這個鏈接

希望它為您提供所需的功能。

問題解決了:我不得不關閉Comunication Logging

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM