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


Java IoBuffer.allocate方法代码示例

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


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

示例1: send

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/***
 * Sends a msgpack message to the provider.
 * @param val msgpack encoded message
 */
private synchronized void send(Value val) {
    logger.debug("Sending packet", val);
    if (!session.isConnected())
        logger.warn("Trying to send when session is not connected.");
    Packer packer = Packer.getPacker();
    try {
        packer.packValue(val);
    } catch (IOException e) {
        throw new RuntimeException("Failed to pack value");
    }
    byte[] encodedPacket = packer.toByteArray();
    IoBuffer buffer = IoBuffer.allocate(encodedPacket.length);
    buffer.put(encodedPacket);
    buffer.flip();
    session.write(buffer);
}
 
开发者ID:cheahjs,项目名称:JLoopix,代码行数:21,代码来源:LoopixClient.java

示例2: sessionOpened

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void sessionOpened ( final NextFilter nextFilter, final IoSession session ) throws Exception
{
    logger.debug ( "Session opened: {}", session );

    final IoBuffer buffer = IoBuffer.allocate ( 1 );
    buffer.setAutoExpand ( true );

    buffer.put ( new byte[] { 0x11, (byte)0xE0, 0x00, 0x00, 0x00, 0x01, 0x00, (byte)0xC1, 2, 1, 0, (byte)0xC2, 2, 0, 1, (byte)0xC0, 1, 9 } );

    buffer.put ( 13, (byte) ( this.rack + 1 ) );
    buffer.put ( 14, this.slot );

    buffer.flip ();

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

示例3: handleWrite

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void handleWrite ( final Variant value )
{
    final MemoryRequestBlock block = this.block;

    if ( block == null )
    {
        throw new IllegalStateException ( "Device is not connected" );
    }

    final T cvtValue = getValue ( value );
    if ( cvtValue != null )
    {
        final IoBuffer data = IoBuffer.allocate ( this.accessor.getBufferSize ( cvtValue ) );
        if ( this.order != null )
        {
            this.order.put ( data, this.accessor, cvtValue );
        }
        else
        {
            this.accessor.put ( data, cvtValue );
        }
        block.writeData ( toAddress ( this.index ), data.array () );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:26,代码来源:AbstractAccessorAttribute.java

示例4: performRead

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private IoBuffer performRead ( final int offset, final int length )
{
    logger.debug ( "Perform read - offset: {}, length: {}, capacity: {}", offset, length, this.buffer.capacity () );

    if ( length == 0 )
    {
        return null;
    }

    if ( offset < 0 )
    {
        return null;
    }

    if ( offset + length > this.buffer.capacity () )
    {
        return null;
    }

    final IoBuffer result = IoBuffer.allocate ( length );

    result.put ( this.buffer.getSlice ( offset, length ) );

    return result;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:26,代码来源:MemoryBlock.java

示例5: sessionOpened

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void sessionOpened(IoSession session) throws Exception {
	String ipAddr = SessionManager.INSTANCE.getRemoteIp(session);
	if (!isInWhiteIps(ipAddr)) {
		logger.error("非法后台登录,remoteIp=[{}]", ipAddr);
		byte[] body = "too young too simple".getBytes("UTF-8");
		IoBuffer out = IoBuffer.allocate(body.length);
		out.put(body);
		out.flip();
		session.write(out);
		session.close(false);
	}
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:14,代码来源:HttpServer.java

示例6: BitRequest

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
public BitRequest ( final byte area, final short block, final short start, final boolean[] bits )
{
    super ( AddressType.BIT, area, block, start, (short)bits.length );
    this.data = IoBuffer.allocate ( bits.length );

    for ( int i = 0; i < bits.length; i++ )
    {
        this.data.put ( bits[i] ? (byte)0x01 : (byte)0x00 );
    }

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

示例7: encode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * 基本信息编码
 * */
@Override
public void encode(IoSession session, BaseMessage message,ProtocolEncoderOutput outPut) throws Exception {
	
	
	IoBuffer buffer = IoBuffer.allocate(1024);
	//创建自动缩小的Buffer  Buffer会保持在上面设置的1024*1024*1,但是一旦需求超过会自动增加容量
	buffer.setAutoExpand(true);
	//传入数据类型
	buffer.putInt(message.getDataType());
	//存储的业务数据
	StringBean bean = (StringBean) message.getData();
	//文件名
	byte[] byteStr = bean.getFileName().getBytes(BeanUtil.charset);
	
	//传入文件名长度
	buffer.putInt(byteStr.length);
	//传入文件名
	//CharSequence charSequrnce = "你好";
	//CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
	//buffer.putString(charSequrnce, encoder);
	buffer.put(byteStr);
	//打包,归0数组指针
	buffer.flip();
	//发送
	outPut.write(buffer);
	log.debug("编码完成");
	//自动调整一下buffer的内存空间
	buffer.shrink();
}
 
开发者ID:Xvms,项目名称:xvms,代码行数:33,代码来源:StringProtocolEncoder.java

示例8: 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

示例9: finishDecode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public DecodingState finishDecode(ProtocolDecoderOutput out) throws Exception {
    IoBuffer product;
    // When input contained only CR or LF rather than actual data...
    if (buffer == null) {
        product = IoBuffer.allocate(0);
    } else {
        product = buffer.flip();
        buffer = null;
    }
    return finishDecode(product, out);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:ConsumeToCrLfDecodingState.java

示例10: makeReadReply

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
protected Object makeReadReply ( final BaseMessage baseMessage, final int[] data, final ByteOrder order )
{
    final IoBuffer reply = IoBuffer.allocate ( data.length * 2 );

    reply.order ( order );

    for ( int i = 0; i < data.length; i++ )
    {
        reply.putUnsignedShort ( data[i] );
    }
    reply.flip ();
    return new ReadResponse ( baseMessage.getTransactionId (), baseMessage.getUnitIdentifier (), baseMessage.getFunctionCode (), reply );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:14,代码来源:SlaveHost.java

示例11: write

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void write(int b) throws IOException {
    IoBuffer buf = IoBuffer.allocate(1);
    buf.put((byte) b);
    buf.flip();
    write(buf);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:IoSessionOutputStream.java

示例12: finishDecode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public DecodingState finishDecode(ProtocolDecoderOutput out) throws Exception {
    IoBuffer readData;
    if (buffer == null) {
        readData = IoBuffer.allocate(0);
    } else {
        readData = buffer.flip();
        buffer = null;
    }
    return finishDecode(readData, out);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:14,代码来源:FixedLengthDecodingState.java

示例13: encode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput out ) throws Exception
{
    logger.debug ( "Encoding: {}", message );
    final Pdu request = (Pdu)message;

    final IoBuffer buffer = IoBuffer.allocate ( request.getData ().remaining () + 3 );
    buffer.setAutoExpand ( true );

    final IoBuffer pdu = request.getData ();

    // put slave id
    buffer.put ( request.getUnitIdentifier () );
    // put data
    buffer.put ( pdu );

    // make and put crc
    final int crc = Checksum.crc16 ( buffer.array (), 0, pdu.limit () + 1 ); // including slave address
    buffer.order ( ByteOrder.LITTLE_ENDIAN );
    buffer.putShort ( (short)crc );

    buffer.flip ();

    logger.trace ( "Encoded to: {}", buffer );

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

示例14: encode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput out ) throws Exception
{
    logger.debug ( "Encoding: {}", message );
    final Pdu request = (Pdu)message;

    final IoBuffer buffer = IoBuffer.allocate ( request.getData ().remaining () + 7 );
    buffer.setAutoExpand ( true );

    final IoBuffer pdu = request.getData ();

    // put transaction identifier
    buffer.putUnsignedShort ( request.getTransactionId () );
    // put modbus protocol identifier (always 0)
    buffer.putUnsignedShort ( 0 );
    // put length, including slave id
    buffer.putUnsignedShort ( request.getData ().remaining () + 1 );
    // put slave id
    buffer.put ( request.getUnitIdentifier () );
    // put data
    buffer.put ( pdu );

    buffer.flip ();

    logger.trace ( "Encoded to: {}", buffer );

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

示例15: finishDecode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public DecodingState finishDecode(ProtocolDecoderOutput out) throws Exception {
    IoBuffer product;
    // When input contained only terminator rather than actual data...
    if (buffer == null) {
        product = IoBuffer.allocate(0);
    } else {
        product = buffer.flip();
        buffer = null;
    }
    return finishDecode(product, out);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:ConsumeToDynamicTerminatorDecodingState.java


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