2017-07-07 13 views
0

okhttpの使用中にこのエラーが発生しました。私は、エラーの理由を分析するのに役立ち、私に例外:gzipが消耗元なしで完了しました。Okhttp、okioについて

スロー新しいのIOException( "gzipでは排出せずに終了したソリューション

@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 here CH.pngを教えてくださいソース");

+0

ようこそ。 [ツアー](https://stackoverflow.com/tour)、[How to Ask](https://stackoverflow.com/questions/how-to-ask)を読んで、最も重要なことはこの特定のケースで編集してくださいあなたの質問に[最小、完全、および検証可能な例](https://stackoverflow.com/help/mcve)を含めるようにしてください。このコメントの有用性は、私ではなく@OldProgrammerに役立ちます。写真の有用性に関する古い格言は、必ずしも真実ではありません。 – jeff6times7

答えて

0

JakeWharton BillBosiolis

OK。これは閉鎖することができます。 retrofit/OkHttpとは何の関係もありません。

実際、チャンクエンコーディングが使用されている場合でも、サーバーコード(Apacheではなく)が常にContent-Lengthヘッダーを返すという問題があったようです。

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

関連する問題