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


Java IoBuffer.reset方法代码示例

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


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

示例1: decodable

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public MessageDecoderResult decodable(IoSession session, IoBuffer buf) {
	int remain = buf.remaining();
	if(remain <= 1){
		return  MessageDecoderResult.NOT_OK;
	}
	buf.mark();
	byte[] data = new byte[remain - 2];
	buf.get(data);
	byte cs = buf.get();
	int t = 0;
	for( int i =0; i< data.length; i ++){
		t += data[i];
	}
	int cs_cal = (t%256) ;
	
	//如果校验码校验不通过,则为无效消息
	if ( (cs & 0xFF) != (cs_cal & 0xFF)){
		buf.reset();
		return MessageDecoderResult.NOT_OK;
	}
	buf.reset();
	return MessageDecoderResult.OK;
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:25,代码来源:MessageTcpDecoder.java

示例2: getMessageCopy

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private Object getMessageCopy(Object message) {
    Object messageCopy = message;
    if (message instanceof IoBuffer) {
        IoBuffer rb = (IoBuffer) message;
        rb.mark();
        IoBuffer wb = IoBuffer.allocate(rb.remaining());
        wb.put(rb);
        wb.flip();
        rb.reset();
        messageCopy = wb;
    }
    return messageCopy;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:14,代码来源:VmPipeFilterChain.java

示例3: writeBuffer

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private int writeBuffer(S session, WriteRequest req, boolean hasFragmentation, int maxLength, long currentTime)
        throws Exception {
    IoBuffer buf = (IoBuffer) req.getMessage();
    int localWrittenBytes = 0;

    if (buf.hasRemaining()) {
        int length;

        if (hasFragmentation) {
            length = Math.min(buf.remaining(), maxLength);
        } else {
            length = buf.remaining();
        }

        try {
            localWrittenBytes = write(session, buf, length);
        } catch (IOException ioe) {
            // We have had an issue while trying to send data to the 
            // peer : let's close the session.
            session.close(true);
        }

    }

    session.increaseWrittenBytes(localWrittenBytes, currentTime);

    if (!buf.hasRemaining() || (!hasFragmentation && (localWrittenBytes != 0))) {
        // Buffer has been sent, clear the current request.
        int pos = buf.position();
        buf.reset();

        fireMessageSent(session, req);

        // And set it back to its position
        buf.position(pos);
    }

    return localWrittenBytes;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:40,代码来源:AbstractPollingIoProcessor.java

示例4: flush

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private boolean flush( S session, long currentTime ) throws Exception
{
    final WriteRequestQueue writeRequestQueue = session.getWriteRequestQueue();
    final int maxWrittenBytes = session.getConfig().getMaxReadBufferSize()
        + ( session.getConfig().getMaxReadBufferSize() >>> 1 );

    int writtenBytes = 0;

    try
    {
        for ( ;; )
        {
            WriteRequest req = session.getCurrentWriteRequest();

            if ( req == null )
            {
                req = writeRequestQueue.poll( session );

                if ( req == null )
                {
                    setInterestedInWrite( session, false );
                    break;
                }

                session.setCurrentWriteRequest( req );
            }

            IoBuffer buf = ( IoBuffer ) req.getMessage();

            if ( buf.remaining() == 0 )
            {
                // Clear and fire event
                session.setCurrentWriteRequest( null );
                buf.reset();
                session.getFilterChain().fireMessageSent( req );
                continue;
            }

            SocketAddress destination = req.getDestination();

            if ( destination == null )
            {
                destination = session.getRemoteAddress();
            }

            int localWrittenBytes = send( session, buf, destination );

            if ( ( localWrittenBytes == 0 ) || ( writtenBytes >= maxWrittenBytes ) )
            {
                // Kernel buffer is full or wrote too much
                setInterestedInWrite( session, true );

                return false;
            }
            else
            {
                setInterestedInWrite( session, false );

                // Clear and fire event
                session.setCurrentWriteRequest( null );
                writtenBytes += localWrittenBytes;
                buf.reset();
                session.getFilterChain().fireMessageSent( req );
            }
        }
    }
    finally
    {
        session.increaseWrittenBytes( writtenBytes, currentTime );
    }

    return true;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:74,代码来源:AbstractPollingConnectionlessIoAcceptor.java

示例5: decode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public MessageDecoderResult decode(IoSession session, IoBuffer buf, ProtocolDecoderOutput out) throws Exception {
	CjyTcpMessage message = new CjyTcpMessage();
	logger.info("收到采集仪消息" + buf.getHexDump());
	buf.mark();
	//帧起始符 0x68
	buf.get();
	// 获取设备编码
	int address_i = buf.getInt();
	message.setAddress(CommUtils.highAndLowAddressSwap(address_i));
	//帧起始符 0x16
	if ( buf.get() != 0x68){
		return null;
	}
	//控制码
	byte control = buf.get();
	message.setD7(control >> 7);
	message.setD6(control >> 6);
	
	//控制码 , 协议簇
	message.setCmd(control&0x0f);
	//数据体长度
	int length = buf.get();
	message.setLength(length);
	//数据体
	byte[] data = MessageUtil.getBytes(buf, length);
	message.setData(data);
	//CRC
	byte crc = (buf.get());
	//结束标志
	int finished = buf.get();
	if ( finished != 0x16 ){
		return MessageDecoderResult.NOT_OK;
	}
	buf.reset();
	//获取校验位前字节
	byte[] cpData = MessageUtil.getBytes(buf, 8 + length);
	int t = 0;
	for( int i =0; i< cpData.length; i ++){
		t += cpData[i];
	}
	int crc_cal = (t%256) ;
	
	logger.info("获取的CRC值" + (crc & 0xFF) + ",计算的crc值:" + crc_cal + ",address:" + message.getAddress());
	//如果校验码校验不通过,则为无效消息
	if ( (crc & 0xFF) != (crc_cal & 0xFF)){
		return MessageDecoderResult.NOT_OK;
	}
	buf.get();
	buf.get();
	out.write(message);
	return MessageDecoderResult.OK;
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:54,代码来源:MessageTcpDecoder.java


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