當前位置: 首頁>>代碼示例>>Java>>正文


Java IoBuffer.getInt方法代碼示例

本文整理匯總了Java中org.apache.mina.core.buffer.IoBuffer.getInt方法的典型用法代碼示例。如果您正苦於以下問題:Java IoBuffer.getInt方法的具體用法?Java IoBuffer.getInt怎麽用?Java IoBuffer.getInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.mina.core.buffer.IoBuffer的用法示例。


在下文中一共展示了IoBuffer.getInt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processWriteResult

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private boolean processWriteResult ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
    final int len = messageLength ( data );
    if ( len < 0 )
    {
        return false;
    }

    try
    {
        final int operationId = data.getInt ();
        final int errorCode = data.getUnsignedShort ();
        final String errorMessage = decodeString ( session, data );

        out.write ( new WriteResult ( operationId, errorCode, errorMessage ) );
    }
    catch ( final CharacterCodingException e )
    {
        throw new ProtocolCodecException ( e );
    }

    return true;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:24,代碼來源:ProtocolDecoderImpl.java

示例2: decode

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void decode ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput output ) throws Exception
{
    final short magic = data.getShort ();
    final byte version = data.get ();
    final int sequence = data.getInt ();
    final byte commandCode = data.get ();

    if ( magic != 1202 )
    {
        throw new ProtocolCodecException ( String.format ( "Magic code should be 1202 but is %s", magic ) );
    }
    if ( version != 1 )
    {
        throw new ProtocolCodecException ( String.format ( "Version should be %s but is %s", 1, version ) );
    }

    decodeMessage ( sequence, commandCode, data, output );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:20,代碼來源:ArduinoCodec.java

示例3: decodeEnumList

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public <E extends Enum<E>> List<E> decodeEnumList ( final IoBuffer buffer, final Class<E> enumClazz ) throws Exception
{
    final byte type = checkType ( buffer, TYPE_ENUM_LIST, true );
    if ( type == TYPE_NULL )
    {
        return null;
    }

    final int len = buffer.getInt ();
    final List<E> result = new ArrayList<E> ( len );
    for ( int i = 0; i < len; i++ )
    {
        result.add ( inlineDecodeEnum ( buffer, enumClazz ) );
    }

    return result;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:19,代碼來源:DefaultBinaryContext.java

示例4: decodeBooleanCollection

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private <T extends Collection<Boolean>> T decodeBooleanCollection ( final IoBuffer buffer, final CollectionAllocator<Boolean, T> allactor ) throws Exception
{
    final byte type = checkType ( buffer, TYPE_BOOLEAN_LIST, true );

    if ( type == TYPE_NULL )
    {
        return null;
    }
    else
    {
        final int items = buffer.getInt ();
        final T result = allactor.allocate ( items );
        fillBooleanCollection ( buffer, items, result );
        return result;
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:17,代碼來源:DefaultBinaryContext.java

示例5: decodeMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.ae.data.message.StartBrowse decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
    // message code
    {
        final int messageCode = _data.getInt ();

        if ( messageCode != MESSAGE_CODE )
        {
            throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
        }
    }

    final byte numberOfFields = _data.get ();

    // decode attributes

    logger.trace ( "Decoding {} fields", numberOfFields );

    for ( int i = 0; i < numberOfFields; i++ )
    {

        final byte fieldNumber = _data.get ();
        switch ( fieldNumber )
        {
            default:
                logger.warn ( "Received unknown field number: {}", fieldNumber );
                break;
        }

    }

    // create object
    return new org.eclipse.scada.ae.data.message.StartBrowse ();
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:36,代碼來源:StartBrowse.java

示例6: decodeMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.hd.data.message.StartBrowse decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
    // message code
    {
        final int messageCode = _data.getInt ();

        if ( messageCode != MESSAGE_CODE )
        {
            throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
        }
    }

    final byte numberOfFields = _data.get ();

    // decode attributes

    logger.trace ( "Decoding {} fields", numberOfFields );

    for ( int i = 0; i < numberOfFields; i++ )
    {

        final byte fieldNumber = _data.get ();
        switch ( fieldNumber )
        {
            default:
                logger.warn ( "Received unknown field number: {}", fieldNumber );
                break;
        }

    }

    // create object
    return new org.eclipse.scada.hd.data.message.StartBrowse ();
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:36,代碼來源:StartBrowse.java

示例7: beginReadStructureList

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public Integer beginReadStructureList ( final IoBuffer buffer, final boolean allowNull ) throws Exception
{
    final byte type = checkType ( buffer, TYPE_STRUCTURE_LIST, allowNull );
    if ( type == TYPE_NULL )
    {
        return null;
    }

    return buffer.getInt ();
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:12,代碼來源:DefaultBinaryContext.java

示例8: decodable

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public MessageDecoderResult decodable(IoSession session, IoBuffer in)
{
	
	Context context = (Context) session.getAttribute(CONTEXT);
	if(context!=null){
		if(context.limit_data){
			in.buf().position(0);
		}
	}
	//表示數據不夠,需要讀到新的數據後,再次調用decode()方法。
	if (in.remaining() < 2){
		return MessageDecoderResult.NEED_DATA;
	}
	else{
			context = new Context();
			//獲取一個字符表示新的數據開始 用於判斷異常數據
			in.skip(1);//這個數據是十六進製的 01 也就是1
			//獲取第一個字符用於判斷是否可以被當前解碼器解碼
			context.dataType = in.getInt();
			
			if(context.dataType == BeanUtil.UPLOAD_STR){
				//讀取標題長度
				context.strLength = in.getInt();
				//聲明數組長度
				context.byteStr = new byte[context.strLength];
				//System.out.println("我收到2了");
				session.setAttribute(CONTEXT, context);
				//表示可以解碼
				return MessageDecoderResult.OK;
			}else{
				//System.out.println("服務端收到意外數據");
				return MessageDecoderResult.NOT_OK;
			}
		}
}
 
開發者ID:Xvms,項目名稱:xvms,代碼行數:37,代碼來源:StringProtocolDecoder.java

示例9: inlineDecodeProperties

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
protected Map<String, String> inlineDecodeProperties ( final IoBuffer buffer ) throws Exception
{
    final int len = buffer.getInt ();
    final Map<String, String> result = new HashMap<String, String> ( len );
    for ( int i = 0; i < len; i++ )
    {
        final String key = this.stringInterner.intern ( buffer.getPrefixedString ( STRING_PREFIX_LEN, this.decoder ) );
        final String value = this.stringInterner.intern ( buffer.getPrefixedString ( STRING_PREFIX_LEN, this.decoder ) );
        result.put ( key, value );
    }
    return result;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:13,代碼來源:DefaultBinaryContext.java

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

示例11: decodeMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.ae.data.message.UpdateQueryData decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
    // message code
    {
        final int messageCode = _data.getInt ();

        if ( messageCode != MESSAGE_CODE )
        {
            throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
        }
    }

    final byte numberOfFields = _data.get ();

    // decode attributes

    long queryId = 0L;
    java.util.List<org.eclipse.scada.ae.data.EventInformation> events = null;

    logger.trace ( "Decoding {} fields", numberOfFields );

    for ( int i = 0; i < numberOfFields; i++ )
    {

        final byte fieldNumber = _data.get ();
        switch ( fieldNumber )
        {
            case 1:
            {
                queryId = _context.decodePrimitiveLong ( _data );
            }
                break;
            case 2:
            {
                events = org.eclipse.scada.ae.protocol.ngp.codec.Structures.decodeListEventInformation ( _context, _data, true );
            }
                break;
            default:
                logger.warn ( "Received unknown field number: {}", fieldNumber );
                break;
        }

    }

    // create object
    return new org.eclipse.scada.ae.data.message.UpdateQueryData ( queryId, events );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:49,代碼來源:UpdateQueryData.java

示例12: decodeMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.da.data.message.WriteValueResult decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
    // message code
    {
        final int messageCode = _data.getInt ();

        if ( messageCode != MESSAGE_CODE )
        {
            throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
        }
    }

    final byte numberOfFields = _data.get ();

    // decode attributes

    org.eclipse.scada.core.data.Response response = null;
    org.eclipse.scada.core.data.ErrorInformation errorInformation = null;

    logger.trace ( "Decoding {} fields", numberOfFields );

    for ( int i = 0; i < numberOfFields; i++ )
    {

        final byte fieldNumber = _data.get ();
        switch ( fieldNumber )
        {
            case 1:
            {
                response = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeResponse ( _context, _data, false );
            }
                break;
            case 2:
            {
                errorInformation = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeErrorInformation ( _context, _data, true );
            }
                break;
            default:
                logger.warn ( "Received unknown field number: {}", fieldNumber );
                break;
        }

    }

    // create object
    return new org.eclipse.scada.da.data.message.WriteValueResult ( response, errorInformation );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:49,代碼來源:WriteValueResult.java

示例13: doDecode

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
protected boolean doDecode ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput output ) throws Exception
{
    logger.trace ( "decode data - session: {}, data: {}", session, data );

    if ( data.remaining () < HEADER_SIZE )
    {
        return false;
    }

    final int position = data.position ();

    final byte version = data.get ( position ); // peek at version
    if ( version != 0x01 )
    {
        throw new IllegalStateException ( String.format ( "Version 0x%02x is not supported.", version ) );
    }

    final int frameTypeOrdinal = data.get ( position + 1 ); // peek at frame type
    final FrameType frameType = FrameType.values ()[frameTypeOrdinal]; // may case an exception, that is ok then

    final int dataLength = data.getInt ( position + 2 ); // we need to look at "here" + 2

    logger.trace ( "Data length: {}, remainingData: {}", dataLength, data.remaining () - 6 );

    if ( data.remaining () < HEADER_SIZE + dataLength )
    {
        return false;
    }

    // consume fields
    data.get (); // version - #0
    data.get (); // frame type - #1
    data.getInt (); // dataLength - #2

    // data - #6
    final IoBuffer frameData = data.getSlice ( dataLength ); // this also consumes the buffer 'data'

    final Frame frame = new Frame ( frameType, frameData );

    logger.trace ( "Decoded frame: {} ... {} bytes remaining", frame, data.remaining () );
    output.write ( frame );

    return true;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:46,代碼來源:FrameDecoder.java

示例14: decodeMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.da.data.message.BrowseFolder decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
    // message code
    {
        final int messageCode = _data.getInt ();

        if ( messageCode != MESSAGE_CODE )
        {
            throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
        }
    }

    final byte numberOfFields = _data.get ();

    // decode attributes

    org.eclipse.scada.core.data.Request request = null;
    java.util.List<String> location = null;

    logger.trace ( "Decoding {} fields", numberOfFields );

    for ( int i = 0; i < numberOfFields; i++ )
    {

        final byte fieldNumber = _data.get ();
        switch ( fieldNumber )
        {
            case 1:
            {
                request = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeRequest ( _context, _data, false );
            }
                break;
            case 2:
            {
                location = _context.decodeStringList ( _data );
            }
                break;
            default:
                logger.warn ( "Received unknown field number: {}", fieldNumber );
                break;
        }

    }

    // create object
    return new org.eclipse.scada.da.data.message.BrowseFolder ( request, location );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:49,代碼來源:BrowseFolder.java

示例15: decodeMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.hd.data.message.CreateQueryFailure decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
    // message code
    {
        final int messageCode = _data.getInt ();

        if ( messageCode != MESSAGE_CODE )
        {
            throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
        }
    }

    final byte numberOfFields = _data.get ();

    // decode attributes

    org.eclipse.scada.core.data.Response response = null;
    org.eclipse.scada.core.data.ErrorInformation errorInformation = null;

    logger.trace ( "Decoding {} fields", numberOfFields );

    for ( int i = 0; i < numberOfFields; i++ )
    {

        final byte fieldNumber = _data.get ();
        switch ( fieldNumber )
        {
            case 1:
            {
                response = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeResponse ( _context, _data, false );
            }
                break;
            case 2:
            {
                errorInformation = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeErrorInformation ( _context, _data, false );
            }
                break;
            default:
                logger.warn ( "Received unknown field number: {}", fieldNumber );
                break;
        }

    }

    // create object
    return new org.eclipse.scada.hd.data.message.CreateQueryFailure ( response, errorInformation );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:49,代碼來源:CreateQueryFailure.java


注:本文中的org.apache.mina.core.buffer.IoBuffer.getInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。