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

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

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

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

代码示例来源:origin: org.apache.directory.mina/mina-core

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

代码示例来源:origin: org.apache.directory.server/mitosis

protected void encodeBody( BaseMessage in, ByteBuffer out )
{
  LoginMessage m = ( LoginMessage ) in;
  try
  {
    out.putString( m.getReplicaId(), utf8encoder );
  }
  catch ( CharacterCodingException e )
  {
    throw new RuntimeException( e );
  }
}

代码示例来源:origin: org.apache.directory.server/mitosis

protected void encodeBody( BaseMessage in, ByteBuffer out ) throws Exception
{
  LoginAckMessage m = ( LoginAckMessage ) in;
  super.encodeBody( in, out );
  out.putString( m.getReplicaId(), utf8encoder );
}

代码示例来源:origin: org.apache.directory.mina/mina-core

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.apache.directory.server/mitosis

private void writeCSNVector( ByteBuffer out, CSNVector csns )
{
  Set<String> replicaIds = csns.getReplicaIds();
  int nReplicas = replicaIds.size();
  out.putInt( nReplicas );
  for ( String replicaId:replicaIds )
  {
    CSN csn = csns.getCSN( replicaId );
    
    try
    {
      out.putString( replicaId, utf8encoder );
      out.put( ( byte ) 0x00 );
      out.putLong( csn.getTimestamp() );
      out.putInt( csn.getOperationSequence() );
    }
    catch ( CharacterCodingException e )
    {
      throw new RuntimeException( e );
    }
  }
}

代码示例来源:origin: org.apache.directory.mina/mina-core

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

相关文章