1

I encountered this error while using okhttp. Please help me analyze the reason for the error and give me a solution

 @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 finished without exhausting source");

Arison
  • 15
  • 7
  • Welcome to SO. Please take the [tour](https://stackoverflow.com/tour), read [How to Ask](https://stackoverflow.com/questions/how-to-ask), and most importantly in this specific case edit your question to include a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Any of this comment's helpfulness goes to @OldProgrammer, not me. The old adage about a picture's usefulness is not always true. – Jeff Holt Jul 07 '17 at 02:36

1 Answers1

0

JakeWharton BillBosiolis

OK. This one can be closed. It has nothing to do with retrofit/OkHttp.

In fact, it seems that the problem was that the server code (not Apache) was always sending a Content-Length header back even in cases where chunked encoding was being used.

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

Arison
  • 15
  • 7