public static ChannelData decode(byte binMessage[],char offset) throws StunException {
  char msgLen=0;
  char channelNumber=0;
  ChannelData channelData=null;
  byte data[]=null;
  if ((binMessage.length - offset) < HEADER_LENGTH) {
    throw new StunException(StunException.ILLEGAL_ARGUMENT,"Size too short");
  }
  channelNumber=(char)((binMessage[offset++] << 8) | (binMessage[offset++] & 0xFF));
  if (!validateChannelNumber(channelNumber)) {
    throw new StunException(StunException.ILLEGAL_ARGUMENT,"Channel number invalid");
  }
  msgLen=(char)((binMessage[offset++] << 8) | (binMessage[offset++] & 0xFF));
  if (msgLen > (binMessage.length - offset)) {
    throw new StunException(StunException.ILLEGAL_ARGUMENT,"Size mismatch");
  }
  data=new byte[msgLen];
  System.arraycopy(binMessage,offset,data,0,msgLen);
  channelData=new ChannelData();
  channelData.setData(data);
  channelData.setChannelNumber(channelNumber);
  return channelData;
}

public static ChannelData decode ( byte binMessage [ ] , char offset ) throws StunException { char msgLen = 0 ; char channelNumber = 0 ; ChannelData channelData = null ; byte data [ ] = null ; if ( ( binMessage . length - offset ) < HEADER_LENGTH ) { throw new StunException ( StunException . ILLEGAL_ARGUMENT , "Size too short" ) ; } channelNumber = ( char ) ( ( binMessage [ offset ++ ] << 8 ) | ( binMessage [ offset ++ ] & 0xFF ) ) ; if ( ! validateChannelNumber ( channelNumber ) ) { throw new StunException ( StunException . ILLEGAL_ARGUMENT , "Channel number invalid" ) ; } msgLen = ( char ) ( ( binMessage [ offset ++ ] << 8 ) | ( binMessage [ offset ++ ] & 0xFF ) ) ; if ( msgLen > ( binMessage . length - offset ) ) { throw new StunException ( StunException . ILLEGAL_ARGUMENT , "Size mismatch" ) ; } data = new byte [ msgLen ] ; System . arraycopy ( binMessage , offset , data , 0 , msgLen ) ; channelData = new ChannelData ( ) ; channelData . setData ( data ) ; channelData . setChannelNumber ( channelNumber ) ; return channelData ; }
constructs a message from its binary representation .
