title: Java Implementing htonl
body: <p>I am communicating with a server, each message sent to the server has to be padded with the length of the message,</p>
  
  <pre><code>unsigned int len = htonl(msg.size());
  </code></pre>
  
  <p>In C running the length through <code>htonl</code> and padding the message works, in Java AFAIK byte order is already in network order so I assumed all I have to do is write the string length before the message to the stream, but this does not work am I missing something?</p>
  
  <pre><code>stream.write(msg.length());
  stream.write(msg.getBytes());
  </code></pre>
  
  <p>Stream is an <code>OutputStream</code>.</p>