title: InputStream not receiving EOF
body: <p>I am attempting to send an image from my android device to my computer via a socket. The problem is the input stream on my computer reads in every single byte but the last set of them.  I have tried trimming the byte array down and sending it, I've manually written out -1 to the outputstream multiple times but the inputstream never reads -1.  It just hangs waiting for data.  I've also tried not closing the stream or sockets to see if it was some sort of timing issue, but that didn't work as well.</p>
  
  <p>Client side (Android Phone)</p>
  
  <pre><code>//This has to be an objectoutput stream because I write objects to it first
  InputStream is = An image's input stream android
  ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
  objectOutputStream.writeObject(object);
  objectOutputStream.flush();
  
  byte[] b = new byte[socket.getSendBufferSize()];
  int read = 0;
  while ((read = is.read(b)) != -1) {
     objectOutputStream.write(b, 0, read);
     objectOutputStream.flush();
     b = new byte[socket.getSendBufferSize()];
  }
  //Tried manually writing -1 and flushing here
  objectOutputStream.close();
  is.close();
  socket.close();
  </code></pre>
  
  <p>Server Side (Computer)  This bit of code takes place after the object input stream reads in the objects sent.  It only starts to read when the file starts to send</p>
  
  <pre><code>File loc = Location of where the file is stored on the computer
  loc.createNewFile();
  FileOutputStream os = new FileOutputStream(loc);
  Socket gSocket = The socket
  ObjectInputStream gInputStream = Object Input stream created from the sockets input stream already used to read in the previous objects
  
  byte[] b = new byte[gSocket.getReceiveBufferSize()];
  int read = 0;
  while ((read = gInputStream.read(b)) != -1) {
     os.write(b, 0, read);
     os.flush();
     b = new byte[gSocket.getReceiveBufferSize()];
  }
  
  os.close();
  </code></pre>
  
  <p>This code never reads in -1 even if I write -1 directly and flush the stream.  The outcome is java.net.SocketException: Connection reset when the stream or socket from the android device is closed.  The picture is almost completely sent but the very last pixels of the picture are gray.  I also even tried using the out/input stream directly from the socket instead of using the already created objectinputstream/objectoutputstream and it still doesn't work.</p>