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

  • Home
  • SEARCH
  • 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 9163349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:25:33+00:00 2026-06-17T14:25:33+00:00

Below is my method where I pass in as a parameter java.net.Socket:getInputStream(). This works

  • 0

Below is my method where I pass in as a parameter java.net.Socket:getInputStream().

This works perfectly well at almost all times.

Problem occurs when input stream from the socket is a big chunk of empty bytes (ambiguous data). This makes my program to stop responding altogether. Does anyone know what’s going on? Should I not get IOException or something rather than just stop responding? How can I just quit the read if e.g. data is some useless ambiguous information.

public static String fromStream(InputStream in) throws IOException
{
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder out = new StringBuilder();
    String line;
    while ((line = reader.readLine()) != null) {
        out.append(line);
    }
    return out.toString();
}
  • 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-17T14:25:34+00:00Added an answer on June 17, 2026 at 2:25 pm

    The $64,000 question is what is this “meaningless ambiguous data”?

    If it is truly meaningless, then you should really be focussing on why it is being sent. The chances are that it is caused by a bug in the application that is sending the data. Find and fix that, and you don’t need to change your client code.

    On the other hand, it could be meaningful data … but you / your application don’t know what it means. In that case, the root problem is that the file is not a text file, and it is therefore incorrect to read it using a Reader / BufferedReader.

    If you want to persist with trying to read this data as text … in such a way that the zero bytes / characters don’t cause you grief, then you need to read from the BufferedReader one character at a time. When you encounter a zero character (or bad ones) your character reading code can bail out. Otherwise, assemble the non-bad characters into lines if that is what you actually need.


    There are a couple of things to note from your comment:

    I was basically just expecting normal response e.g. including 200 i.e. OK from the HTTP server, where in this exceptional case I get these zero bytes and nothing else at all.

    Firstly, it sounds like you might be trying to interact with an HTTP server using plain sockets. This is a bad idea. A really bad idea! The chances are that you plain socket code will not be able to correctly interpret the various different ways that a kosher HTTP server could send a response. (And that would explain the following …)

    Secondly, an HTTP response includes a “Content-type” that gives you the media type of stuff in the response body. If your client ignores the Content-type header, you risk processing the response body the wrong way. For instance, you might get a PDF file or a TAR file which could certainly contain large numbers of zero bytes.

    On the other hand, you could be doing these things the right way, and the HTTP server could just be broken.

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

Sidebar

Related Questions

Why I must pass parameter to static Method with private access control in Java.
In the code below I pass method B as an action to be perfomed
Why can't you pass an anonymous method as a parameter to the BeginInvoke method?
If my method call is: obj.getLevelOne().getLevelTwo().getValue(); And I want to pass this method as
Lets say I have this program below. Now I want to pass both the
Possible Duplicate: Java pass by reference issue In my codes below, methodA will be
I can pass multiple parameters and at last one block parameter to method. But
I have the below method which is meant to append information to a file
I'm using the below method to reply to mails coming in to a business
I have the below method: public String tryGoogleAuthentication(String auth_token){ ContactsService contactsService = new ContactsService(.....);

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.