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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:23:17+00:00 2026-06-03T09:23:17+00:00

i got a problem in parsing when i use HTTPGET specially TIMEOUT handling and

  • 0

i got a problem in parsing when i use HTTPGET specially TIMEOUT handling and get response trough HttpResponse and passto xmlR.parse(new InputSource(instream)); and make rest procedure. but there are throw error:

05-08 11:03:38.637: WARN/System.err(522): java.io.IOException: Attempted read on closed stream.
05-08 11:03:38.667: WARN/System.err(522):     at org.apache.http.conn.EofSensorInputStream.isReadAllowed(EofSensorInputStream.java:127)
05-08 11:03:38.667: WARN/System.err(522):     at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:176)
05-08 11:03:38.677: WARN/System.err(522):     at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:515)
05-08 11:03:38.677: WARN/System.err(522):     at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:478)
05-08 11:03:38.677: WARN/System.err(522):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:317)
05-08 11:03:38.677: WARN/System.err(522):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
05-08 11:03:38.677: WARN/System.err(522):     at com.housedisplay.mapspec.MyMapActivity.Sendsarchparameter(MyMapActivity.java:334)
05-08 11:03:38.687: WARN/System.err(522):     at com.housedisplay.mapspec.MyMapActivity.access$0(MyMapActivity.java:289)
05-08 11:03:38.697: WARN/System.err(522):     at com.housedisplay.mapspec.MyMapActivity$SearchATask.doInBackground(MyMapActivity.java:251)
05-08 11:03:38.697: WARN/System.err(522):     at com.housedisplay.mapspec.MyMapActivity$SearchATask.doInBackground(MyMapActivity.java:1)
05-08 11:03:38.697: WARN/System.err(522):     at android.os.AsyncTask$2.call(AsyncTask.java:252)
05-08 11:03:38.697: WARN/System.err(522):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-08 11:03:38.697: WARN/System.err(522):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-08 11:03:38.697: WARN/System.err(522):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
05-08 11:03:38.697: WARN/System.err(522):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
05-08 11:03:38.697: WARN/System.err(522):     at java.lang.Thread.run(Thread.java:1020)

Code:: (timeout code based on this answer by kuester2000)

HttpGet httpGet = new HttpGet(strURL.toURI());
            HttpParams httpParameters = new BasicHttpParams();
            // Set the timeout in milliseconds until a connection is established.
            // The default value is zero, that means the timeout is not used. 
            int timeoutConnection = 3000;
            HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
            // Set the default socket timeout (SO_TIMEOUT) 
            // in milliseconds which is the timeout for waiting for data.
            int timeoutSocket = 5000;
            HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

            DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
            HttpResponse response = httpClient.execute(httpGet);
            
            
            HttpEntity entity = response.getEntity();
            InputStream instream = entity.getContent();
            if (entity != null) {
                
                strResponse = convertStreamToString(instream);

                
            }
        /**********test*******/
            SAXParserFactory saxPF = SAXParserFactory.newInstance();
            
            SAXParser saxP = saxPF.newSAXParser();
            XMLReader xmlR = saxP.getXMLReader();
            System.out.println("url >>>>>" + strURL);
            HandlerFromLatLongCustom myXMLHandler = new HandlerFromLatLongCustom();
            xmlR.setContentHandler(myXMLHandler);
            xmlR.parse(new InputSource(instream));
            instream.close();
  • 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-03T09:23:19+00:00Added an answer on June 3, 2026 at 9:23 am

    I suspect this is the problem:

    strResponse = convertStreamToString(instream);
    

    My guess is that that method (which you haven’t shown) closes the stream. Aside from anything else, it will at least have read the stream, which will make it hard to read again later on…

    You can either read the entire response into a byte array, which you can then wrap in as many ByteArrayInputStreams as you want, or you could use strResponse as the source to parse. That could raise encoding issues though.

    It’s possible that HttpClient will do all this for you – that you can simply write:

    instream = entity.getContent();
    

    and get the same data again – I don’t know enough about the details around whether the stream returned is effectively “live” or whether the client code reads the data and caches it.

    Also note that this code is extremely suspicious:

    HttpEntity entity = response.getEntity();
    InputStream instream = entity.getContent();
    if (entity != null) {
        ...
    

    If entity is null, the second line will already have thrown a NullPointerException, making the check on the third line pretty pointless…

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

Sidebar

Related Questions

I've got a problem with &amp when I use XML parsing with webservices which
I have some problem with JSON parsing. When I hit URL, I've got JSON
I've got some problems parsing the response of a Last.fm API call from a
I'm building a system for reading emails in C#. I've got a problem parsing
i got problem with my code and hopefully someone able to figure it out.
I got problem with sending data in Android using httpPost. I found some example,
I've got problem with connecting to MySQL database on my freshly installed Windows 7
I want to ask about strcpy. I got problem here. Here is my code:
Got a problem with a query I'm trying to write. I have a table
Got a problem with ComponentListener. I'm using it to check if a certain component

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.