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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:09:03+00:00 2026-06-11T13:09:03+00:00

I make a http get request to server via HttpURLConnection and I need to

  • 0

I make a http get request to server via HttpURLConnection and I need to read response (InputStream) twice: for logging purposes and for parsing response. The returned InputStraem is instance of org.apache.harmony.luni.internal.net.www.protocol.http.ChunkedInputStream which doesn’t support marking (is.markSupported() return false).

Therefore I can’t mark() and reset() stream and after writing response in log I can’t parse it. Ofcourse I can read response once into String or something else, log them and later parse. But when i’m working with streams i’m avoiding potentially OutOfMemomryError because streams deals with buffering instead of me.

What is the best solution in this case which will keep the benefits of using streams and help to achieve the desired result: the simultaneous recording into the log and parsing response?

EDIT: Solution with writing response into temporary file isn’t appropriate

  • 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-11T13:09:04+00:00Added an answer on June 11, 2026 at 1:09 pm

    I’m not sure I fully understand, you’d like to read the InputStream once (not really twice that’s a bit unclean IMO, because what if an error occurs only on the log stream and not the stream you are parsing?) and then simply log and parse the same InputStream?

    If the above is the case here pseudo to show the solution:

    InputStream is=...;
    byte[] bytes=new byte[1028];
    while(is.read(bytes)!=-1) {
    log(bytes); //call function to log
    parse(bytes);//call function to parse
    }
    

    even better for simultaneous logging and recording would be creating a new Thread/Runnable for both methods, starting them and wait for them to return using (thread.join();):

    InputStream is=...;
    byte[] bytes=new byte[1028];
    while(is.read(bytes)!=-1) {
    Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
              log(bytes); //call function to log
            }
        });
    Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
               parse(bytes);//call function to parse
            }
        });
         t1.start();
         t2.start();
    try {
         t1.join();
         t2.join();
        }catch(Exception ex) {
          ex.printStackTrace();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make an HTTP request to get back translated text. If I
I need to use a GET request to send JSON to my server via
I tried to make http get request with code: String username = test\\v100; String
What is the best way to make an HTTP GET request in Ruby with
I'm trying to make this request to the RunKeeper API : GET /user HTTP/1.1
I am trying to connect with google via oauth V2 I make http request
I would like to make a http get request with my Android phone (i
i first tried to make request to server with GET method and it works
I need to make an HTTP POST request from outside the browser, but the
I am working with Titanium Studio and I have to make an HTTP get

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.