简体   繁体   中英

Play framework 2 Java, return chunked response

Based on the following code example that returns chunked data from Play server, the out.write shouldn't create response each time it is called? when using post client I get only 1 response which contains that wholl data with all the data.

I need to return a huge file from the server in chunks which should be downloaded in the client. Any ideas?

public static Result index(){ 
// Prepare a chunked text stream 
Chunks<String> chunks = new StringChunks() 
{ 
    // Called when the stream is ready 
    public void onReady(Chunks.Out<String> out) 
    { 
        out.write("kiki");
        out.write("foo");
        out.write("bar");
        out.close();
     }
 };// Serves this stream with 200 OK 
return ok(chunks); 
} 

The amount of chunks depends on the chunk size, which usually defaults to 1024 KB throughout the framework. Your output is too small and thus only one chunk is sent.

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