【问题标题】:An exception:gzip finished without exhausting source, about Okhttp,okio异常:gzip 未穷尽源码完成,关于 Okhttp,okio
【发布时间】:2017-12-11 05:06:32
【问题描述】:

我在使用 okhttp 时遇到了这个错误。请帮我分析错误原因并给我解决方案

 @Override public long read(Buffer sink, long byteCount) throws IOException { 
if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount); 
if (byteCount == 0) return 0; 

// If we haven't consumed the header, we must consume it before anything else. 
if (section == SECTION_HEADER) { 
  consumeHeader(); 
  section = SECTION_BODY; 
} 

// Attempt to read at least a byte of the body. If we do, we're done. 
if (section == SECTION_BODY) { 
  long offset = sink.size; 
  long result = inflaterSource.read(sink, byteCount); 
  if (result != -1) { 
    updateCrc(sink, offset, result); 
    return result; 
  } 
  section = SECTION_TRAILER; 
} 

// The body is exhausted; time to read the trailer. We always consume the 
// trailer before returning a -1 exhausted result; that way if you read to 
// the end of a GzipSource you guarantee that the CRC has been checked. 
if (section == SECTION_TRAILER) { 
  consumeTrailer(); 
  section = SECTION_DONE; 

  // Gzip streams self-terminate: they return -1 before their underlying 
  // source returns -1. Here we attempt to force the underlying stream to 
  // return -1 which may trigger it to release its resources. If it doesn't 
  // return -1, then our Gzip data finished prematurely! 
 if (!source.exhausted()) { 
    throw new IOException("gzip finished without exhausting source"); 
  }
} 

return -1; 

}

enter image description here

enter image description hereCH.png

throw new IOException("gzip 完成但没有耗尽源");

【问题讨论】:

  • 欢迎来到 SO。请使用tour,阅读How to Ask,最重要的是在这种特定情况下编辑您的问题以包含Minimal, Complete, and Verifiable example。这条评论的任何帮助都归于@OldProgrammer,而不是我。关于图片有用的古老格言并不总是正确的。

标签: okhttp okio


【解决方案1】:

杰克沃顿 比尔博西奥利斯

好的。这个可以关闭。与改造/OkHttp无关。

事实上,问题似乎在于,即使在使用分块编码的情况下,服务器代码(而不是 Apache)总是会发回 Content-Length 标头。

https://github.com/square/retrofit/issues/1170

【讨论】:

    猜你喜欢
    • 2016-02-26
    • 2013-04-20
    • 1970-01-01
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 2016-04-07
    相关资源
    最近更新 更多