public byte[] encode(boolean pad) throws StunException {
  int dataLength=getDataLength();
  if (pad)   dataLength=padTo4(dataLength);
  byte binMsg[]=new byte[HEADER_LENGTH + dataLength];
  int offset=0;
  if (!validateChannelNumber(channelNumber)) {
    throw new StunException(StunException.ILLEGAL_ARGUMENT,"Channel number invalid");
  }
  binMsg[offset++]=(byte)(channelNumber >> 8);
  binMsg[offset++]=(byte)(channelNumber & 0xff);
  binMsg[offset++]=(byte)((data != null) ? data.length >> 8 : 0);
  binMsg[offset++]=(byte)((data != null) ? data.length & 0xff : 0);
  if (data != null) {
    System.arraycopy(data,0,binMsg,offset,data.length);
  }
  return binMsg;
}

public byte [ ] encode ( boolean pad ) throws StunException { int dataLength = getDataLength ( ) ; if ( pad ) dataLength = padTo4 ( dataLength ) ; byte binMsg [ ] = new byte [ HEADER_LENGTH + dataLength ] ; int offset = 0 ; if ( ! validateChannelNumber ( channelNumber ) ) { throw new StunException ( StunException . ILLEGAL_ARGUMENT , "Channel number invalid" ) ; } binMsg [ offset ++ ] = ( byte ) ( channelNumber > > 8 ) ; binMsg [ offset ++ ] = ( byte ) ( channelNumber & 0xff ) ; binMsg [ offset ++ ] = ( byte ) ( ( data != null ) ? data . length > > 8 : 0 ) ; binMsg [ offset ++ ] = ( byte ) ( ( data != null ) ? data . length & 0xff : 0 ) ; if ( data != null ) { System . arraycopy ( data , 0 , binMsg , offset , data . length ) ; } return binMsg ; }
returns a binary representation of this message .
