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