#CR8 Java - unexpected EOF

I’m stuck on Stage #CR8 using Java

No matter what I do I’m always getting unexpected EOF, even if I hardcode the response. I also copy pasted solution from another person and still getting error. My binary seems to be empty somehow…

Here are my logs:

[tester::#CR8] Received bytes: "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 6\r\nContent-Encoding: gzip\r\n\r\n\x1f\x8b\b\x00\x00\x00"
[tester::#CR8] < HTTP/1.1 200 OK
[tester::#CR8] < Content-Type: text/plain
[tester::#CR8] < Content-Length: 6
[tester::#CR8] < Content-Encoding: gzip
[tester::#CR8] < 
[tester::#CR8] < <Binary Content>
[tester::#CR8] < 
[tester::#CR8] Received response with 200 status code
[tester::#CR8] ✓ Content-Encoding header is present
[tester::#CR8] ✓ Content-Length header is present
[tester::#CR8] Failed to decode gzip: Failed to decompress data: unexpected EOF

And here’s a snippet of my code:

if (resEncodingList.contains("gzip")) {
  byte[] resBodyBytes = GzipCompressor.compress(getResBody(response));
  outStream = socket.getOutputStream();
  String echoStr = "pinapple";
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream)) {
    System.out.println("TRY successful");
  byte[] gzipData = byteArrayOutputStream.toByteArray();


Ok, so it seems my issue was that I didn’t update content length to be length oof compressed data and instead I was using length of uncompressed string.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.