本文整理匯總了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 );
}