code: public static byte[] recv(InputStream in, int size) throws IOException {
  		byte [] bytes = new byte [size];
  		int numRead = in.read(bytes);
  		if(numRead==-1) {
  			throw new IOException("premature end of data");
  		}
  		while (numRead < size) {
  		  int len = in.read(bytes, numRead, size - numRead);
  		  if(len==-1) {
  			  throw new IOException("premature end of data");
  		  }
  		  numRead+=len;
  		}
  		return bytes;
  	}
docs: Receive a message of the given size from the inputstream.
  Makes sure the complete message is received, raises IOException otherwise.