[英]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? 根据以下从Play服务器返回分块数据的代码示例,
out.write
不应在每次调用时创建响应吗? when using post client I get only 1 response which contains that wholl data with all the data. 使用post client时,我仅收到1条响应,其中包含该数据和所有数据。
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. 块的数量取决于块的大小,在整个框架中,块的大小通常默认为1024 KB。 Your output is too small and thus only one chunk is sent.
您的输出太小,因此仅发送了一个块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.