本文整理汇总了Java中org.apache.mina.core.buffer.IoBuffer.putFloat方法的典型用法代码示例。如果您正苦于以下问题:Java IoBuffer.putFloat方法的具体用法?Java IoBuffer.putFloat怎么用?Java IoBuffer.putFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.core.buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.putFloat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeWriteRequest
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void encodeWriteRequest ( final IoBuffer data, final WriteRequestMessage message )
{
data.putShort ( message.getIndex () );
final Object value = message.getData ();
if ( value == null )
{
data.put ( (byte)0x00 );
}
else if ( value instanceof Boolean )
{
data.put ( (byte)0x01 );
data.put ( (byte) ( (Boolean)value ? 0xFF : 0x00 ) );
}
else if ( value instanceof Float || value instanceof Double )
{
data.put ( (byte)0x04 );
data.putFloat ( ( (Number)value ).floatValue () );
}
else if ( value instanceof Long )
{
data.put ( (byte)0x03 );
data.putLong ( ( (Number)value ).longValue () );
}
else if ( value instanceof Number )
{
data.put ( (byte)0x02 );
data.putInt ( ( (Number)value ).intValue () );
}
else if ( value instanceof String )
{
data.put ( (byte)0x02 );
data.putInt ( Integer.parseInt ( (String)value ) );
}
else
{
throw new RuntimeException ( String.format ( "Unable to write request of type %s", value.getClass () ) );
}
}
示例2: sendWriteFloatData
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@SuppressWarnings ( "unused" )
private void sendWriteFloatData ()
{
final float f = this.r.nextFloat ();
logger.info ( "Sending float: {}", f );
final DaveWriteRequest request = new DaveWriteRequest ();
this.tix++;
final IoBuffer data = IoBuffer.allocate ( 4 );
data.putFloat ( f );
data.flip ();
request.addRequest ( new DaveWriteRequest.ByteRequest ( (byte)0x84, (short)1, (short)214, data ) );
this.session.write ( request );
}