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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:32:04+00:00 2026-05-26T16:32:04+00:00

Hi i have a problem i’m not able to solve. In my Android\java application

  • 0

Hi i have a problem i’m not able to solve.
In my Android\java application i call a script download.php. Basically it gives a file in output that i download and save on my device. I had to add a control on all my php scripts that basically consist in sending a token to the script and check if it’s valid or not. If it’s a valid token i will get the output (in this case a file in the other scripts a json file) if it’s not i get back a string “false”.

To check this condition in my other java files i used IOUtils method to turn the input stream to a String, check it, and than

InputStream newInputStream = new ByteArrayInputStream(mystring.getBytes("UTF-8"));

to get a valid input stream again and read it……it works with my JSon files, but not in this case……i get this error:

11-04 16:50:31.074: ERROR/AndroidRuntime(32363):
java.lang.OutOfMemoryError

when i try IOUtils.toString(inputStream, "UTF-8");

I think it’s because in this case i’m trying to download really long file.

fileOutput = new BufferedOutputStream(new FileOutputStream(file,false));
inputStream = new BufferedInputStream(conn.getInputStream());

String result = IOUtils.toString(inputStream, "UTF-8");
if(result.equals("false"))
{
     return false;
}
else
{
    Reader r = new InputStreamReader(MyMethods.stringToInputStream(result));
    int totalSize = conn.getContentLength();
    int downloadedSize = 0;
    byte[] buffer = new byte[1024];
    int bufferLength = 0;
    while ( (bufferLength = inputStream.read(buffer)) > 0 ) 
    {
        fileOutput.write(buffer, 0, bufferLength);
            downloadedSize += bufferLength;
}
fileOutput.flush();
fileOutput.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-05-26T16:32:04+00:00Added an answer on May 26, 2026 at 4:32 pm

    Don’t read the stream as a string to start with. Keep it as binary data, and start off by just reading the first 5 bytes. You can then check whether those 5 bytes are the 5 bytes used to encode “false” in UTF-8, and act accordingly if so. Otherwise, write those 5 bytes to the output file and then do the same looping/reading/writing as before. Note that to read those 5 bytes you may need to loop (however unlikely that seems). Perhaps your IOUtils class has something to say “read at least 5 bytes”? Will the real content ever be smaller than 5 bytes?

    To be honest, it would be better if you could use a header in the response to indicate the different result, instead of just a body with “false” – are you in control of the PHP script?

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

Sidebar

Related Questions

I have problem with date function in php. If I supply string in format
i have problem i can't solve for a while. For one of my C++
I have problem with handling dynamically created Buttons on Android. I'm creating N buttons
I have problem running my app on Android 2.3 (Gingerbread). The app has a
I have problem in Listview onListItemClick() method. I am not getting the position of
I have problem with this exception: Hibernate.HibernateException : Could not create the driver from
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE

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.