当前位置: 首页>>代码示例>>Java>>正文


Java IoBuffer.putInt方法代码示例

本文整理汇总了Java中org.apache.mina.core.buffer.IoBuffer.putInt方法的典型用法代码示例。如果您正苦于以下问题:Java IoBuffer.putInt方法的具体用法?Java IoBuffer.putInt怎么用?Java IoBuffer.putInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.core.buffer.IoBuffer的用法示例。


在下文中一共展示了IoBuffer.putInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput output ) throws Exception
{
    if ( ! ( message instanceof Frame ) )
    {
        throw new IllegalStateException ( String.format ( "Can only encode messages of type Frame but got %s", message.getClass () ) );
    }

    final Frame frame = (Frame)message;

    if ( logger.isTraceEnabled () )
    {
        logger.trace ( "Encode frame - type: {}, data: {}", frame.getType (), frame.getData () );
    }

    final IoBuffer buffer = IoBuffer.allocate ( 1 + 1 + 4 + frame.getData ().remaining () );
    buffer.put ( (byte)0x01 ); // version - #0
    buffer.put ( (byte)frame.getType ().ordinal () ); // frame type - #1
    buffer.putInt ( frame.getData ().remaining () ); // data size - #2
    buffer.put ( frame.getData () ); // data - #6
    buffer.flip ();

    output.write ( buffer );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:FrameEncoder.java

示例2: readObject

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
public Object readObject() throws ClassNotFoundException, IOException {
    int objectSize = in.readInt();
    if (objectSize <= 0) {
        throw new StreamCorruptedException("Invalid objectSize: " + objectSize);
    }
    if (objectSize > maxObjectSize) {
        throw new StreamCorruptedException("ObjectSize too big: " + objectSize + " (expected: <= " + maxObjectSize
                + ')');
    }

    IoBuffer buf = IoBuffer.allocate(objectSize + 4, false);
    buf.putInt(objectSize);
    in.readFully(buf.array(), 4, objectSize);
    buf.position(0);
    buf.limit(objectSize + 4);

    return buf.getObject(classLoader);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:ObjectSerializationInputStream.java

示例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 );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DefaultBinaryContext.java

示例4: encodeLongCollection

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void encodeLongCollection ( final IoBuffer buffer, final byte fieldNumber, final Collection<Long> data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_LONG_LIST );
        buffer.putInt ( data.size () );
        for ( final Long entry : data )
        {
            buffer.putLong ( entry );
        }
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DefaultBinaryContext.java

示例5: encodeIntCollection

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void encodeIntCollection ( final IoBuffer buffer, final byte fieldNumber, final Collection<Integer> data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_INT_LIST );
        buffer.putInt ( data.size () );
        for ( final Integer entry : data )
        {
            buffer.putInt ( entry );
        }
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DefaultBinaryContext.java

示例6: encodeBooleanCollection

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void encodeBooleanCollection ( final IoBuffer buffer, final byte fieldNumber, final Collection<Boolean> data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_BOOLEAN_LIST );
        buffer.putInt ( data.size () );
        // FIXME: encode as bit array
        for ( final Boolean entry : data )
        {
            buffer.put ( entry ? (byte)0xFF : (byte)0x00 );
        }
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:20,代码来源:DefaultBinaryContext.java

示例7: encodeVariantCollection

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void encodeVariantCollection ( final IoBuffer buffer, final byte fieldNumber, final Collection<Variant> data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_VARIANT_LIST );
        buffer.putInt ( data.size () );
        for ( final Variant entry : data )
        {
            inlineEncodeVariant ( buffer, entry );
        }
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DefaultBinaryContext.java

示例8: writeMessage

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private IoBuffer writeMessage(Message message) {
	//----------------消息协议格式-------------------------
	// packetLength | moduleId | cmd   |  body
	//       int       short     short    byte[]

	IoBuffer buffer = IoBuffer.allocate(CodecContext.WRITE_CAPACITY);
	buffer.setAutoExpand(true);

	//消息内容长度,先占个坑
	buffer.putInt(0);
	short moduleId = message.getModule();
	short cmd = message.getCmd();
	//写入module类型
	buffer.putShort(moduleId);
	//写入cmd类型
	buffer.putShort(cmd);

	//写入具体消息的内容
	byte[] body = wrapMessageBody(moduleId, cmd, message);
	buffer.put(body);
	//回到buff字节数组头部
	buffer.flip();
	//消息元信息,两个short,共4个字节
	final int METE_SIZE = 4;
	//重新写入包体长度
	buffer.putInt(buffer.limit() - METE_SIZE);
	buffer.rewind();

	return buffer;
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:31,代码来源:MessageEncoder.java

示例9: makeSimpleData

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private IoBuffer makeSimpleData ( final int value )
{
    final IoBuffer d = IoBuffer.allocate ( 4 );
    d.putInt ( value );
    d.flip ();
    return d;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:FrameDecoderTest.java

示例10: 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 () ) );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:39,代码来源:ArduinoCodec.java

示例11: encodeHeader

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void encodeHeader ( final IoBuffer data, final CommonMessage message )
{
    data.putShort ( (short)1202 );
    data.put ( (byte)0x01 );
    data.putInt ( message.getSequence () );
    data.put ( message.getCommandCode ().getCommandCode () );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:ArduinoCodec.java

示例12: 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 );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:10,代码来源:DefaultBinaryContext.java

示例13: encodeMessage

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public IoBuffer encodeMessage ( final BinaryContext context, final Object objectMessage ) throws Exception
{
    final IoBuffer data = IoBuffer.allocate ( 5 );
    data.putInt ( MESSAGE_CODE );
    data.put ( (byte)0 ); // number of fields 

    data.flip ();
    return data;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:11,代码来源:StopBrowse.java

示例14: beginWriteStructureList

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void beginWriteStructureList ( final IoBuffer buffer, final byte fieldNumber, final Collection<?> values ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( values != null )
    {
        buffer.put ( TYPE_STRUCTURE_LIST );
        buffer.putInt ( values.size () );
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:DefaultBinaryContext.java

示例15: encodePrimitiveInt

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void encodePrimitiveInt ( final IoBuffer buffer, final byte fieldNumber, final int data ) throws Exception
{
    buffer.put ( fieldNumber );
    buffer.put ( TYPE_INT );
    buffer.putInt ( data );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:DefaultBinaryContext.java


注:本文中的org.apache.mina.core.buffer.IoBuffer.putInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。