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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:50:02+00:00 2026-05-30T23:50:02+00:00

I have an Android application where I’m trying to send a picture to a

  • 0

I have an Android application where I’m trying to send a picture to a server. I did this using Base64 encoding and it worked quite well, but it took too much memory (and time) to encode the picture before sending it.

I’m trying to strip the Android application down to where it just simply sends the byte array and doesn’t fiddle around with any kind of encoding scheme so it’ll save as much memory and CPU cycles as possible.

This is what I would like the Android code to look like:

public String sendPicture(byte[] picture, String address) {
    try {
        Socket clientSocket = new Socket(address, 8000);
        OutputStream out = clientSocket.getOutputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        out.write(picture);
        return in.readLine();
    }
    catch(IOException ioe) {
        Log.v("test", ioe.getMessage());
    }
    return " ";
}

The server is written in Java. How do I write the server code so I can properly retrieve the exact same byte array? My goal is to save as many CPU cycles on the Android as possible.

So far, all the methods I’ve tried resulted in corrupt data or a thrown exception.

Any help will be appreciated.

  • 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-30T23:50:03+00:00Added an answer on May 30, 2026 at 11:50 pm

    Based on Robert’s and Zaki’s comment, here is the modified code that should perform better.

    public byte[] getPicture(InputStream in) {
      try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] data = new byte[1024];
        int length = 0;
        while ((length = in.read(data))!=-1) {
            out.write(data,0,length);
        }
           return out.toByteArray();
        } catch(IOException ioe) {
        //handle it
       }
       return null;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this android application that requires to load data from a remote server
I have a Web Service and an Android application that uses this web service.
I have Android application which is Sales Rep application.When he using the app first
I have an Android application with this lines in the manifest: <uses-sdk android:minSdkVersion=8 android:targetSdkVersion=13/>
I have an Android application and within it some strings which I send through
I have android application that I need to debug using eclipse. When I right
I have an android application which (over the network) communicates with a desktop server
I have an android application, I'm trying to put a splash screen in via
I have develop android application using Android SDK, Eclipse IDE.In that some times showing
I have an android application which uses jni and I'm trying to automate build

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.