title: Java/Android: Reading/writing a byte array over a socket
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>This is what I would like the Android code to look like:</p>
  
  <pre><code>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 " ";
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>So far, all the methods I've tried resulted in corrupt data or a thrown exception.</p>
  
  <p>Any help will be appreciated.</p>