【问题标题】:Play framework 2 Java, return chunked response播放框架 2 Java,返回分块响应
【发布时间】:2014-09-14 13:50:23
【问题描述】:

基于以下从 Play 服务器返回分块数据的代码示例, out.write 不应该在每次调用时都创建响应? 使用 post 客户端时,我只收到 1 个响应,其中包含所有数据的全部数据。

我需要从服务器以块的形式返回一个巨大的文件,该文件应该下载到客户端。 有什么想法吗?

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); 
} 

【问题讨论】:

    标签: java playframework-2.0 chunks


    【解决方案1】:

    块的数量取决于块的大小,通常在整个框架中默认为 1024 KB。您的输出太小,因此只发送了一个块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多