public void visiteErrorCode(final ErrorCodeAttribute attribute) {
    writeHeader(attribute);

    // The first 21 bits are zero-filled for 32 bit alignment.  We skip
    // the first 16 here so we can just write a full byte for the class
    // on the next call.
    m_buf.skip(2);
    MinaUtils.putUnsignedByte(this.m_buf, attribute.getErrorClass());
    MinaUtils.putUnsignedByte(this.m_buf, attribute.getErrorNumber());
    try {
      m_buf.putString(attribute.getReasonPhrase(), UTF_8_ENCODER);
    } catch (final CharacterCodingException e) {
      LOG.error("Could not encode reason phrase", e);
      throw new IllegalArgumentException("Could not encode reason phrase", e);
    }
  }
  private void visitAddressAttribute(final StunAddressAttribute address) {
    writeHeader(address);

    // Now put the attribute body.

    // The first byte is ignored in address attributes.
    MinaUtils.putUnsignedByte(m_buf, 0x00);

    final int family = address.getAddressFamily();

    if (LOG.isDebugEnabled()) {
      LOG.debug("Writing family: " + family);
    }
    final InetSocketAddress socketAddress = address.getInetSocketAddress();
    final int port = socketAddress.getPort();
    final InetAddress ia = socketAddress.getAddress();
    final byte[] addressBytes = ia.getAddress();
    MinaUtils.putUnsignedByte(m_buf, family);
    MinaUtils.putUnsignedShort(m_buf, port);
    m_buf.put(addressBytes);
  }
 public void visitIcePriority(final IcePriorityAttribute attribute) {
   writeHeader(attribute);
   final long priority = attribute.getPriority();
   MinaUtils.putUnsignedInt(m_buf, priority);
 }
 public void visitConnectionStatus(final ConnectionStatusAttribute attribute) {
   LOG.debug("Writing connection status attribute: {}", attribute);
   writeHeader(attribute);
   final ConnectionStatus status = attribute.getConnectionStatus();
   MinaUtils.putUnsignedInt(m_buf, status.toLong());
 }
 private void writeHeader(final StunAttribute sa) {
   MinaUtils.putUnsignedShort(m_buf, sa.getAttributeType().toInt());
   MinaUtils.putUnsignedShort(m_buf, sa.getBodyLength());
 }