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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:39:36+00:00 2026-06-14T16:39:36+00:00

I used this question How do I convert an InputStream to a String in

  • 0

I used this question

How do I convert an InputStream to a String in Java?

to convert an InputStream to a String with this code:

public static String convertStreamToString(java.io.InputStream is) {
    java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
    return s.hasNext() ? s.next() : "";
} 

My inputstream comes from an HttpURLConnection InputStream, and when I do my conversion to String, the inputstream changes and I cannot longer use it. This is the error that I get:

Premature end of file.' SOAP

What can I do to keep my inputstream, when I convert it to string with the proper information?.

Speciffically this is the information that changes:

inCache = true (before false)
keepAliveConnections = 4 (before 5)
keepingAlive = false (before true)
poster = null (before it was PosterOutputStream object with values)

Thank you.

  • 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-14T16:39:38+00:00Added an answer on June 14, 2026 at 4:39 pm

    If you pass your input stream into scanner or read its data in any other way. you actually consuming its data and there will be no available data in that stream anymore.

    you may need to create a new input stream with same data and use it instead of the original one. for example:

    ByteArrayOutputStream into = new ByteArrayOutputStream();
    byte[] buf = new byte[4096];
    
    // inputStream is your original stream. 
    for (int n; 0 < (n = inputStream.read(buf));) {
        into.write(buf, 0, n);
    }
    into.close();
    
    byte[] data = into.toByteArray();
    
    //This is your data in string format.
    String stringData = new String(data, "UTF-8"); // Or whatever encoding  
    
    //This is the new stream that you can pass it to other code and use its data.    
    ByteArrayInputStream newStream = new ByteArrayInputStream(data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i used this code: List<string> lists=new List<string>(apple,orange,banana,apple,mang0,orange); string names; names=lists.Distinct() is that correct?
In this question , the following code is used - var parent = $(#jcontent);
I used the mapping solution from this question to have a joined component. But
Forgive my ignorance in asking this basic question but I've become so used to
I'm used to MSSQL, not Mysql, so sorry for this probably stupid question. I'm
This is just a curiosity question. I know that Spring can be used in
I'm sure this was asked somewhere in another question, but the wording used there
A while ago I posted this question asking if it's possible to convert text
I have helper component used in multiple classes. This is typical scenario: public class
I just asked this question . Which lead me to a new question :)

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.