本文整理匯總了Java中org.apache.mina.core.buffer.IoBuffer.putPrefixedString方法的典型用法代碼示例。如果您正苦於以下問題:Java IoBuffer.putPrefixedString方法的具體用法?Java IoBuffer.putPrefixedString怎麽用?Java IoBuffer.putPrefixedString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.mina.core.buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.putPrefixedString方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encodeBrowseUpdate
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void encodeBrowseUpdate ( final IoSession session, final Object message, final IoBuffer data ) throws ProtocolCodecException
{
// length
data.putUnsignedShort ( ( (BrowseAdded)message ).getEntries ().size () );
final CharsetEncoder encoder = Sessions.getCharsetEncoder ( session );
// data
for ( final BrowseAdded.Entry entry : ( (BrowseAdded)message ).getEntries () )
{
data.putUnsignedShort ( entry.getRegister () );
data.put ( entry.getDataType ().getDataType () );
data.putEnumSet ( entry.getFlags () );
try
{
data.putPrefixedString ( entry.getName (), encoder );
data.putPrefixedString ( entry.getDescription (), encoder );
data.putPrefixedString ( entry.getUnit (), encoder );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
}
}
示例2: encodeProperties
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void encodeProperties ( final IoBuffer data, final Map<String, String> properties ) throws ProtocolCodecException
{
final CharsetEncoder encoder = this.defaultCharset.newEncoder ();
data.putUnsignedShort ( properties.size () );
for ( final Map.Entry<String, String> entry : properties.entrySet () )
{
try
{
data.putPrefixedString ( entry.getKey (), encoder );
data.putPrefixedString ( entry.getValue (), encoder );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
}
}
示例3: encodeStringCollection
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void encodeStringCollection ( final IoBuffer buffer, final byte fieldNumber, final Collection<String> data ) throws Exception
{
buffer.put ( fieldNumber );
if ( data != null )
{
buffer.put ( TYPE_STRING_LIST );
buffer.putInt ( data.size () );
for ( final String entry : data )
{
buffer.putPrefixedString ( entry, STRING_PREFIX_LEN, this.encoder );
}
}
else
{
buffer.put ( TYPE_NULL );
}
}
示例4: encode
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
String value = (String) message;
IoBuffer buffer = IoBuffer.allocate(value.length()).setAutoExpand(true);
buffer.putPrefixedString(value, prefixLength, charset.newEncoder());
if (buffer.position() > maxDataLength) {
throw new IllegalArgumentException("Data length: " + buffer.position());
}
buffer.flip();
out.write(buffer);
}
示例5: encodeString
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void encodeString ( final IoBuffer buffer, final byte fieldNumber, final String data ) throws Exception
{
buffer.put ( fieldNumber );
if ( data != null )
{
buffer.put ( TYPE_STRING );
buffer.putPrefixedString ( data, STRING_PREFIX_LEN, this.encoder );
}
else
{
buffer.put ( TYPE_NULL );
}
}
示例6: inlineEncodeVariant
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void inlineEncodeVariant ( final IoBuffer buffer, final Variant variant ) throws Exception
{
final VariantType type = variant.getType ();
buffer.putEnum ( type );
switch ( type )
{
case BOOLEAN:
buffer.put ( variant.asBoolean () ? (byte)0xFF : (byte)0x00 );
break;
case DOUBLE:
buffer.putDouble ( variant.asDouble () );
break;
case INT32:
buffer.putInt ( variant.asInteger () );
break;
case INT64:
buffer.putLong ( variant.asLong () );
break;
case STRING:
buffer.putPrefixedString ( variant.asString (), STRING_PREFIX_LEN, this.encoder );
break;
case NULL:
break;
case UNKNOWN:
break;
}
}
示例7: inlineEncodeVariantMap
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
protected void inlineEncodeVariantMap ( final IoBuffer buffer, final Map<String, Variant> data ) throws Exception
{
buffer.putInt ( data.size () );
for ( final Map.Entry<String, Variant> entry : data.entrySet () )
{
buffer.putPrefixedString ( entry.getKey (), STRING_PREFIX_LEN, this.encoder );
inlineEncodeVariant ( buffer, entry.getValue () );
}
}
示例8: inlineEncodeProperties
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
protected void inlineEncodeProperties ( final IoBuffer buffer, final Map<String, String> data ) throws Exception
{
buffer.putInt ( data.size () );
for ( final Map.Entry<String, String> entry : data.entrySet () )
{
buffer.putPrefixedString ( entry.getKey (), STRING_PREFIX_LEN, this.encoder );
buffer.putPrefixedString ( entry.getValue (), STRING_PREFIX_LEN, this.encoder );
}
}
示例9: encodeVariant
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void encodeVariant ( final IoSession session, final IoBuffer data, final Variant value ) throws ProtocolCodecException
{
if ( value == null )
{
data.put ( DataType.DEAD.getDataType () ); // dead
}
else if ( value.isNull () )
{
data.put ( DataType.NULL.getDataType () );
}
else if ( value.isBoolean () )
{
data.put ( DataType.BOOLEAN.getDataType () );
data.put ( (byte) ( value.asBoolean () ? 0xFF : 0x00 ) );
}
else if ( value.isInteger () )
{
data.put ( DataType.INT32.getDataType () );
data.putInt ( value.asInteger ( null ) );
}
else if ( value.isLong () )
{
data.put ( DataType.INT64.getDataType () );
data.putLong ( value.asLong ( null ) );
}
else if ( value.isDouble () )
{
data.put ( DataType.DOUBLE.getDataType () );
data.putDouble ( value.asDouble ( null ) );
}
else if ( value.isString () )
{
data.put ( DataType.STRING.getDataType () );
try
{
data.putPrefixedString ( value.asString ( null ), Sessions.getCharsetEncoder ( session ) );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
}
}