public static int writeMessageFully(Message msg,OutputStream out,ByteBuffer buf,MessageWriter writer) throws IOException {
  assert msg != null;
  assert out != null;
  assert buf != null;
  assert buf.hasArray();
  if (writer != null)   writer.setCurrentWriteClass(msg.getClass());
  boolean finished=false;
  int cnt=0;
  while (!finished) {
    finished=msg.writeTo(buf,writer);
    out.write(buf.array(),0,buf.position());
    cnt+=buf.position();
    buf.clear();
  }
  return cnt;
}

public static int writeMessageFully ( Message msg , OutputStream out , ByteBuffer buf , MessageWriter writer ) throws IOException { assert msg != null ; assert out != null ; assert buf != null ; assert buf . hasArray ( ) ; if ( writer != null ) writer . setCurrentWriteClass ( msg . getClass ( ) ) ; boolean finished = false ; int cnt = 0 ; while ( ! finished ) { finished = msg . writeTo ( buf , writer ) ; out . write ( buf . array ( ) , 0 , buf . position ( ) ) ; cnt += buf . position ( ) ; buf . clear ( ) ; } return cnt ; }
fully writes communication message to provided stream .
