Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8717719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:21:52+00:00 2026-06-13T06:21:52+00:00

I am everything but the most experienced JAVA user, however, I am quite desperate

  • 0

I am everything but the most experienced JAVA user, however, I am quite desperate regarding my problem.
Every time I execute the below code, I receive the following error:

 java.util.zip.ZipException: Not in GZIP format
 at java.util.zip.GZIPInputStream.readHeader(Unknown Source)
 at java.util.zip.GZIPInputStream.(init)(Unknown Source)
 at java.util.zip.GZIPInputStream.(init)(Unknown Source)
 at DidYouMean.executeGet(DidYouMean.java:56)
 at DidYouMean.didYouMean(DidYouMean.java:11)
 at DidYouMean.main(DidYouMean.java:39)
 Exception in thread "main" java.lang.IllegalArgumentException: String input must not be null....

A friend of mine (using a Mac, instead of me using windows 7 64) is able to execute the program. So it appears not to be a problem of the code itself (which was developed by someone on Github anyways). I would really appreciate any help!
My search for a solution has not been very successful, even though the error is not that rare.

import java.io.*;
import java.net.*;
import org.jsoup.*;
import java.util.zip.*;
import org.jsoup.nodes.*;
import org.jsoup.examples.HtmlToPlainText;
public class DidYouMean {
    public static String didYouMean(String s){
        String word="";
        String url="http://www.google.co.in/search?hl=en&q="+URLEncoder.encode(s);
        String html=executeGet(url,"www.google.co.in",'i');
        Document content=Jsoup.parse(html);
        Element submitted=null;
        try{
            submitted=content.getElementById("topstuff").clone();
            HtmlToPlainText h=new HtmlToPlainText();
            word=h.getPlainText(submitted);
            int q,p=word.indexOf("Did you mean:");
            if(p>=0){
                word=word.substring(p+"Did you mean:".length());
                p=word.indexOf("<>");
                if(p>0) word=word.substring(0,p);
                word=word.trim();
            }
            else{
                p=word.indexOf("Showing results for");
                if(p>=0){
                    word=word.substring(p+"Showing results for".length());
                    p=word.indexOf("<>");
                    if(p>0) word=word.substring(0,p);
                    word=word.trim();
                }
                else return "No results";
            }
        }catch(Exception e){e.printStackTrace();}   
        return word;
    }
    public static void main(String args[]){
        System.out.println(didYouMean(args[0]));
    }
    public static String executeGet(String targetURL,String host,char ch){
        URL url;
        HttpURLConnection connection=null;  
        try{
          url=new URL(targetURL);
          connection=(HttpURLConnection)url.openConnection();
          connection.setRequestMethod("GET");
          connection.setRequestProperty("Host",host);
          connection.setRequestProperty("Accept-Encoding", "gzip,deflate,sdch");
          connection.setRequestProperty("Accept-Language","en-US,en;q=0.8");
          if(ch=='c') connection.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5");
          if(ch=='i') connection.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; ShopperReports 3.1.22.0; SRS_IT_E879047EB0765B5336AF90)");
          connection.setUseCaches (false);
          connection.setDoInput(true);
          connection.setDoOutput(true);
          GZIPInputStream gzis=new GZIPInputStream(connection.getInputStream());
          InputStreamReader reader=new InputStreamReader(gzis);
          BufferedReader in=new BufferedReader(reader);
          String line;
          StringBuffer response=new StringBuffer(); 
          while((line=in.readLine())!=null) {
              response.append(line);
              response.append('\r');
          }
          in.close();
          return response.toString();
        } catch (Exception e) {e.printStackTrace();return null;}
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:21:53+00:00Added an answer on June 13, 2026 at 6:21 am
       connection.setRequestProperty("Accept-Encoding", "gzip,deflate,sdch"
    

    Your request says it is willing to accept any of the following encoding formats: gzip, deflate and sdch. One approach is to look at the response-headers to see what type of encoding the server uses and decode it appropriately.

    Another approach is to accept only gzip

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: the user fills in everything but the product name. I need to search
I have nearly tried everything but cannot figure out what is wrong. I have
I have read the docs and everything but I'm very confused. I never needed
I've searched all over and tried everything but I still get: invalid multibyte char
The following bit of code works great in everything but IE. In IE, the
I'm trying to write a regex that will match everything BUT an apostrophe that
How do I check for a click on everything but a certain object? I
I need a regular expression able to match everything but a string starting with
What would be the regex to match — or not match — everything but
I have the following code and it's working (as usual) in everything but IE.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.