org.littleshoot.mina.common.ByteBuffer.putString()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中org.littleshoot.mina.common.ByteBuffer.putString()方法的一些代码示例,展示了ByteBuffer.putString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.putString()方法的具体详情如下:
包路径:org.littleshoot.mina.common.ByteBuffer
类名称:ByteBuffer
方法名:putString

ByteBuffer.putString介绍

[英]Writes the content of in into this buffer as a NUL-terminated string using the specified encoder.

If the charset name of the encoder is UTF-16, you cannot specify odd fieldSize, and this method will append two NULs as a terminator.

Please note that this method doesn't terminate with NUL if the input string is longer than fieldSize.
[中]使用指定的encoderin的内容作为NUL终止的字符串写入此缓冲区。
如果编码器的字符集名称为UTF-16,则不能指定奇数fieldSize,此方法将附加两个NUL作为终止符。
请注意,如果输入字符串长于fieldSize,则此方法不会以NUL终止。

代码示例

代码示例来源:origin: org.littleshoot/mina-port

public ByteBuffer putString(CharSequence in, int fieldSize,
    CharsetEncoder encoder) throws CharacterCodingException {
  buf.putString(in, fieldSize, encoder);
  return this;
}

代码示例来源:origin: org.littleshoot/mina-port

public ByteBuffer putString(CharSequence in, CharsetEncoder encoder)
    throws CharacterCodingException {
  buf.putString(in, encoder);
  return this;
}

代码示例来源:origin: org.littleshoot/sip-stack

private ByteBuffer createDelimiterBuf(final String delimiter)
  {
  ByteBuffer tmp = ByteBuffer.allocate(delimiter.length());
  try
    {
    tmp.putString(delimiter, charset.newEncoder());
    tmp.flip();
    return tmp;
    }
  catch (CharacterCodingException e)
    {
    LOG.error("Bad charset?", e);
    return null;
    }
  }

代码示例来源:origin: org.littleshoot/sip-stack

private void appendHeaderValues(final ByteBuffer buffer,
  final List<SipHeaderValue> values) throws CharacterCodingException
  {
  for (final Iterator<SipHeaderValue> iter = values.iterator(); iter
      .hasNext();)
    {
    final SipHeaderValue value = iter.next();
    buffer.putString(value.getBaseValue(), m_asciiEncoder);
    final Map<String, String> params = value.getParams();
    final Set<Map.Entry<String, String>> entries = params.entrySet();
    for (final Map.Entry<String, String> entry : entries)
      {
      buffer.put(MinaCodecUtils.SEMI_COLON);
      buffer.putString(entry.getKey(), m_asciiEncoder);
      buffer.put(MinaCodecUtils.EQUALS);
      buffer.putString(entry.getValue(), m_asciiEncoder);
      }
    if (iter.hasNext())
      {
      buffer.put(MinaCodecUtils.COMMA);
      }
    }
  }

代码示例来源:origin: org.littleshoot/sip-stack

private void encodeStartLine(final SipMessage message, 
  final ByteBuffer buffer)
  {
  LOG.debug("Encoding start line: '{}'", message.getStartLine());
  try
    {
    buffer.putString(message.getStartLine(), m_asciiEncoder);
    }
  catch (final CharacterCodingException e)
    {
    LOG.error("Bad encoding?", e);
    }
  MinaCodecUtils.appendCRLF(buffer);
  }

代码示例来源:origin: org.littleshoot/mina-port

public void encode(IoSession session, Object message,
    ProtocolEncoderOutput out) throws Exception {
  CharsetEncoder encoder = (CharsetEncoder) session.getAttribute(ENCODER);
  if (encoder == null) {
    encoder = charset.newEncoder();
    session.setAttribute(ENCODER, encoder);
  }
  String value = message.toString();
  ByteBuffer buf = ByteBuffer.allocate(value.length())
      .setAutoExpand(true);
  buf.putString(value, encoder);
  if (buf.position() > maxLineLength) {
    throw new IllegalArgumentException("Line length: " + buf.position());
  }
  buf.putString(delimiter.getValue(), encoder);
  buf.flip();
  out.write(buf);
}

代码示例来源:origin: org.littleshoot/sip-stack

private void encodeHeaders(final SipMessage message, 
  final ByteBuffer buffer)
  {
  LOG.debug("Appending headers: {}", message.getHeaders());
  final Map<String, SipHeader> headers = message.getHeaders();
  for (final Map.Entry<String, SipHeader> entry : headers.entrySet())
    {
    final SipHeader header = entry.getValue();
    final List<SipHeaderValue> values = header.getValues();
    try
      {
      buffer.putString(header.getName(), m_asciiEncoder);
      buffer.put(MinaCodecUtils.COLON);
      buffer.put(MinaCodecUtils.SPACE);
      appendHeaderValues(buffer, values);
      MinaCodecUtils.appendCRLF(buffer);
      }
    catch (final CharacterCodingException e)
      {
      LOG.error("Bad encoding?", e);
      }
    }
  MinaCodecUtils.appendCRLF(buffer);
  }

代码示例来源:origin: org.littleshoot/stun-stack

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);
    }
  }

代码示例来源:origin: org.littleshoot/mina-port

tmp.putString(delimiter.getValue(), charset.newEncoder());
tmp.flip();
delimBuf = tmp;

相关文章