【问题标题】:How to break bigger chunk into smaller ones to fit into max chunk?如何将较大的块分成较小的块以适应最大块?
【发布时间】:2015-02-07 01:11:27
【问题描述】:

我的服务器正在向我发送分块编码数据,我能够在我的客户端中获得分块响应。我面临的问题是有些块太大了,大约 10 MB。由于我已将最大块大小设置为 2M,因此出现异常。

有没有办法把这个大块分成小块?

【问题讨论】:

    标签: spray chunked-encoding transfer-encoding http-chunked


    【解决方案1】:

    嗯。不确定您使用的是什么版本的 Spray,但从 1.1 版开始有 incoming-auto-chunking-threshold-size 设置 (details here)。 Here is 支持分块上传的服务示例。

    目前仍有许多限制。你可以在open ticket阅读相关讨论。

    【讨论】:

      【解决方案2】:

      您可以使用 RandomAccessFile 将大块分成小块。 我有同样的问题。我使用 RandomAccessFile 解决了它。

      您可以按照以下方式进行。

      byte[] bytes;
      String filePath = "path";
      RandomAccessFile file1 = new RandomAccessFile(filePath, "r");
      
            file1.seek(0);
            bytes = new byte[(int)file1.length()/3];
            file1.read(bytes);
            file1.close();
            String str = new String(bytes, "UTF-8");

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-09-21
        • 2014-10-14
        • 2018-03-23
        • 2020-01-14
        • 2020-05-06
        • 2013-11-06
        • 2020-02-05
        相关资源
        最近更新 更多