public byte[] encodeFrame(){
  int length=this.payload.length + frameLengthOverhead;
  if (this.payload.length > 65535) {
    length+=8;
  }
 else   if (this.payload.length >= 126) {
    length+=2;
  }
  ByteBuffer buffer=ByteBuffer.allocate(length);
  appendFinAndOpCode(buffer,this.opcode,this.fin);
  byte mask[]=generateMaskingKey();
  appendLengthAndMask(buffer,this.payload.length,mask);
  for (int i=0; i < this.payload.length; i++) {
    buffer.put((byte)(this.payload[i]^=mask[i % 4]));
  }
  buffer.flip();
  return buffer.array();
}

public byte [ ] encodeFrame ( ) { int length = this . payload . length + frameLengthOverhead ; if ( this . payload . length > 65535 ) { length += 8 ; } else if ( this . payload . length >= 126 ) { length += 2 ; } ByteBuffer buffer = ByteBuffer . allocate ( length ) ; appendFinAndOpCode ( buffer , this . opcode , this . fin ) ; byte mask [ ] = generateMaskingKey ( ) ; appendLengthAndMask ( buffer , this . payload . length , mask ) ; for ( int i = 0 ; i < this . payload . length ; i ++ ) { buffer . put ( ( byte ) ( this . payload [ i ] ^= mask [ i % 4 ] ) ) ; } buffer . flip ( ) ; return buffer . array ( ) ; }
encodes the this websocketframe into a byte array .
