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 6332175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:12:42+00:00 2026-05-24T18:12:42+00:00

I have code that I would like to convert so that I am grabbing

  • 0

I have code that I would like to convert so that I am grabbing my xml from the server in GZIP format. I am not sure how I would send my requests to see if encoding is accepted and what not. Here is some code:

    public void parse(String locCode, int isMetric, String langId) throws IOException, ParserConfigurationException, SAXException {
    //set member variables
    this.locCode    = locCode;
    this.isMetric   = isMetric;
    this.langId     = langId;
    wdm.metric      = isMetric;

    try {
        mCounter++;
        //create input stream from url
        InputStream is = getInputStream(this.locCode, this.isMetric, this.langId);  
        InputSource inputSource = new InputSource(is);

        inputSource.setEncoding(ENCODING_TYPE);

        //create sax parser and xml reader
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        mCounter = 0;
        //pass in instance of FeedParser
        xr.setContentHandler(new WeatherFeedParser());
        xr.parse(inputSource);
        is.close();
    } catch (SocketException e){
        if (mCounter < 3){
            parse(locCode, isMetric, langId);
        }
        else e.printStackTrace();
    } catch (UnknownHostException e){
        if (mCounter < 3){
            parse(locCode, isMetric, langId);
        }
        else e.printStackTrace();
    }

}

private static final InputStream getInputStream(String locCode, int isMetric, String langId) throws IOException {
    //build url
    String addr = FEED_URL + LOCATION + cleanupInput(locCode) + "&" + METRIC + isMetric + "&" + LANG_ID + langId;
    URL url = new URL(addr);

    //create connection
    mCon = url.openConnection();
    mCon.setConnectTimeout((int)ACCUWX.Time._15_SECONDS);
    mCon.setReadTimeout((int)ACCUWX.Time._15_SECONDS);
    mCon.connect();

    return mCon.getInputStream();        
}

I have read other posts and am not sure where I would implement suggestions with this coding:

HttpUriRequest request = new HttpGet(url);
request.addHeader("Accept-Encoding", "gzip");
// ...
httpClient.execute(request);
Check response for content encoding:
InputStream instream = response.getEntity().getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
    instream = new GZIPInputStream(instream);
}
  • 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-05-24T18:12:43+00:00Added an answer on May 24, 2026 at 6:12 pm

    Your second code listing would replace much of the body of your getInputStream() method in your first listing.

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

Sidebar

Related Questions

I have this source code from 2001 that I would like to compile. It
I have some code that raises PropertyChanged events and I would like to be
I have some old C code that I would like to combine with some
I have a few lines of PowerShell code that I would like to use
I have a static method in my code that I would like somehow to
If you have some blocks of code that you would like to prevent execution
I have code, similar to the following, that I would like to modify: Sub
I'd like to write a function that would have some optional code to be
We have a non-standard subversion respository that we would like to convert to Git.
I have byte array as input. I would like to convert that array to

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.