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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:51:34+00:00 2026-05-21T20:51:34+00:00

First, I have a class that extends AsyncTask. Then in the doInBackground() method, I

  • 0

First, I have a class that extends AsyncTask. Then in the doInBackground() method, I have some code that posts an HTTP post message, and gets a response. This response is read into a string as follows:

DataInputStream dis = new DataInputStream(conn.getInputStream());
byte[] data = new byte[32768];
len = dis.read(data, 0, 32768);

if (len > 0)
{
   response = new String(data, 0, len);
}

At this point, response should be 4127 bytes (as confirmed by the server). 1/5th of the time it IS 4127 bytes. 2/5 of the time it’s 1205 bytes, and 2/5 of the time it’s 3853 bytes. I can close the app, reinstall, and I get the same variation.

The person who manages the server logs everything and can confirm the same data is being sent over and over. But Android isn’t getting the full stream. This is wireless, not 3g. When I use the debugger, I can see that the string returned is always identical, just chopped off at a random spot.

Sorry for such a vague (stupid?) question, but I’ve been looking at this for hours and I can’t see what’s wrong with it…

  • 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-21T20:51:35+00:00Added an answer on May 21, 2026 at 8:51 pm

    The read method documentation says: Reads up to len bytes of data from the contained input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.

    Depending on different conditions, sometimes you can read all server-sent data, sometimes there is a short-read. In order to get all data you should keep reading the stream in a loop until len is -1, indicating an EOF.

    InputStream in = ...;
    byte[] dst = new byte[32768]; /* Assuming total len is < 32768 */
    int idx = 0;
    do {
      int len = in.read(dst, idx, 32768 - idx);
      idx += len;
    } while (len >= 0 || idx < 32768);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a class that extends View. I have another class that extends
I design new IntSet Class that use ArrayList. first, i extends Intset by ArrayList
I have a User class and an Author class that extends User. I have
I have First/Last/Previous/Next buttons that change the selected child node of a TreeViewItem. Setting
A few quick searches discovered that I'm obviously not the first person to have
First of all I have to admit that my programming skills are pretty limited
I have an application that when it first starts i need it to run
I have been writing a small java application (my first!), that does only a
I have the following class: <?php /* * Abstract class that, when subclassed, allows
I have an extended dialog class that I want to show for 3 seconds

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.