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


Java ProtocolCodecException类代码示例

本文整理汇总了Java中org.apache.mina.filter.codec.ProtocolCodecException的典型用法代码示例。如果您正苦于以下问题:Java ProtocolCodecException类的具体用法?Java ProtocolCodecException怎么用?Java ProtocolCodecException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: decode

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
public MessageDecoderResult decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out)
        throws ProtocolCodecException {
    int messageCount = 0;
    while (parseMessage(in, out)) {
        messageCount++;
    }
    if (messageCount > 0) {
        // Mina will compact the buffer because we can't detect a header
        if (in.remaining() < HEADER_PATTERN.length) {
            position = 0;
        }
        return MessageDecoderResult.OK;
    } else {
        // Mina will compact the buffer
        position -= in.position();
        return MessageDecoderResult.NEED_DATA;
    }
}
 
开发者ID:fix-protocol-tools,项目名称:STAFF,代码行数:19,代码来源:FixMessageDecoder.java

示例2: decode

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的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: decodeData

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
private Object decodeData ( final IoBuffer data ) throws ProtocolCodecException
{
    data.order ( ByteOrder.LITTLE_ENDIAN );

    final byte dataType = data.get ();
    switch ( dataType )
    {
        case 0:
            return null;
        case 1:
            return data.get () != 0x00;
        case 2:
            return data.getInt ();
        case 3:
            return data.getLong ();
        case 4:
            return data.getFloat ();
        default:
            throw new ProtocolCodecException ( String.format ( "Data type %02x is unknown", dataType ) );
    }

}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:ArduinoCodec.java

示例4: processWriteCommand

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
private boolean processWriteCommand ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
    final int len = messageLength ( data );
    if ( len < 0 )
    {
        return false;
    }

    final int registerNumber = data.getUnsignedShort ();
    final int operationId = data.getInt ();
    final Variant value = decodeVariant ( session, data );

    out.write ( new WriteCommand ( registerNumber, value, operationId ) );

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

示例5: processWriteResult

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的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

示例6: processDataUpdate

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
private boolean processDataUpdate ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
    final int len = messageLength ( data );
    if ( len < 0 )
    {
        return false;
    }

    final int count = data.getUnsignedShort ();
    final List<DataUpdate.Entry> entries = new ArrayList<DataUpdate.Entry> ( count );
    for ( int i = 0; i < count; i++ )
    {
        entries.add ( decodeDataUpdateEntry ( data, session ) );
    }

    out.write ( new DataUpdate ( entries ) );

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

示例7: processBrowseAdded

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
private boolean processBrowseAdded ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
    final int len = messageLength ( data );
    if ( len < 0 )
    {
        return false;
    }

    final int count = data.getUnsignedShort ();

    final List<BrowseAdded.Entry> entries = new ArrayList<BrowseAdded.Entry> ( count );

    for ( int i = 0; i < count; i++ )
    {
        entries.add ( decodeBrowserAddEntry ( data, session ) );
    }

    out.write ( new BrowseAdded ( entries ) );

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

示例8: processHello

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
private boolean processHello ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
    final int len = messageLength ( data );
    if ( len < 0 )
    {
        return false;
    }

    final byte version = data.get ();
    if ( version != 0x01 )
    {
        throw new ProtocolCodecException ( String.format ( "Protocol version %s is unsupported", version ) );
    }

    final short nodeId = data.getShort ();
    final EnumSet<Hello.Features> features = data.getEnumSetShort ( Hello.Features.class );

    out.write ( new Hello ( nodeId, features ) );

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

示例9: encodeBrowseUpdate

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
private void encodeBrowseUpdate ( final IoSession session, final Object message, final IoBuffer data ) throws ProtocolCodecException
{
    // length
    data.putUnsignedShort ( ( (BrowseAdded)message ).getEntries ().size () );

    final CharsetEncoder encoder = Sessions.getCharsetEncoder ( session );

    // data
    for ( final BrowseAdded.Entry entry : ( (BrowseAdded)message ).getEntries () )
    {
        data.putUnsignedShort ( entry.getRegister () );
        data.put ( entry.getDataType ().getDataType () );
        data.putEnumSet ( entry.getFlags () );

        try
        {
            data.putPrefixedString ( entry.getName (), encoder );
            data.putPrefixedString ( entry.getDescription (), encoder );
            data.putPrefixedString ( entry.getUnit (), encoder );
        }
        catch ( final CharacterCodingException e )
        {
            throw new ProtocolCodecException ( e );
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:ProtocolEncoderImpl.java

示例10: encodeProperties

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
private void encodeProperties ( final IoBuffer data, final Map<String, String> properties ) throws ProtocolCodecException
{
    final CharsetEncoder encoder = this.defaultCharset.newEncoder ();

    data.putUnsignedShort ( properties.size () );
    for ( final Map.Entry<String, String> entry : properties.entrySet () )
    {
        try
        {
            data.putPrefixedString ( entry.getKey (), encoder );
            data.putPrefixedString ( entry.getValue (), encoder );
        }
        catch ( final CharacterCodingException e )
        {
            throw new ProtocolCodecException ( e );
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:ProtocolEncoderImpl.java

示例11: checkType

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
private byte checkType ( final IoBuffer buffer, final byte expectedType, final boolean allowNull ) throws Exception
{
    final byte type = buffer.get ();

    if ( allowNull && type == TYPE_NULL )
    {
        return type;
    }

    if ( type != expectedType )
    {
        if ( type == 0 && !allowNull )
        {
            throw new ProtocolCodecException ( String.format ( "Failed to decode. Field is transmitted as null but defined as not-null." ) );
        }

        throw new ProtocolCodecException ( String.format ( "Failed to decode string: Expected type %02x, found: %02x", expectedType, type ) );
    }
    return type;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:21,代码来源:DefaultBinaryContext.java

示例12: extractMessages

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
/**
 * Utility to extract messages from a file. This method will return each
 * message found to a provided listener. The message file will also be
 * memory mapped rather than fully loaded into physical memory. Therefore,
 * a large message file can be processed without using excessive memory.
 *
 * @param file
 * @param listener
 * @throws IOException
 * @throws ProtocolCodecException
 */
public void extractMessages(File file, final MessageListener listener) throws IOException,
        ProtocolCodecException {
    // Set up a read-only memory-mapped file
    FileChannel readOnlyChannel = new RandomAccessFile(file, "r").getChannel();
    MappedByteBuffer memoryMappedBuffer = readOnlyChannel.map(FileChannel.MapMode.READ_ONLY, 0,
            (int) readOnlyChannel.size());

    decode(null, ByteBuffer.wrap(memoryMappedBuffer), new ProtocolDecoderOutput() {

        public void write(Object message) {
            listener.onMessage((String) message);
        }

        public void flush() {
            // ignored
        }

    });
}
 
开发者ID:fix-protocol-tools,项目名称:STAFF,代码行数:31,代码来源:FixMessageDecoder.java

示例13: leaf

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
/**
 * Read a leaf node of a given type and leaf type.
 * 
 * @param type The node type.
 * @param leafType The type of value contained in the leaf: must be
 *                one of the XdrCoding.TYPE_* values.
 * @return The node.
 * 
 * @throws ProtocolCodecException if the node was not valid constant
 *                 node of the specified type.
 */
private Node leaf (int type, int leafType)
  throws ProtocolCodecException
{
  switch (type)
  {
    case NAME:
      assertLeafType (leafType, TYPE_STRING);
      return new Field (getString (in));
    case CONST_STRING:
      assertLeafType (leafType, TYPE_STRING);
      return new Const (getString (in));
    case CONST_INT32:
      assertLeafType (leafType, TYPE_INT32);
      return new Const (in.getInt ());
    case CONST_INT64:
      assertLeafType (leafType, TYPE_INT64);
      return new Const (in.getLong ());
    case CONST_REAL64:
      assertLeafType (leafType, TYPE_REAL64);
      return new Const (in.getDouble ());
    default:
      throw new Error ();
  }
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:36,代码来源:XdrAstParser.java

示例14: encodeAST

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
/**
 * Encode an AST in Elvin XDR format.
 * 
 * @param out The buffer to encode to.
 * @param node The root of the AST.
 * 
 * @see #decodeAST(ByteBuffer)
 */
public static void encodeAST (ByteBuffer out, Node node)
  throws ProtocolCodecException
{
  if (node instanceof Const)
  {
    encodeConst (out, (Const)node);
  } else if (node instanceof Field)
  {
    out.putInt (NAME);
    out.putInt (TYPE_STRING);
    putString (out, ((Field)node).fieldName ());
  } else
  {
    out.putInt (typeCodeFor (node));
    out.putInt (0); // composite node base type is 0
    
    Collection<Node> children = node.children ();
    
    out.putInt (children.size ());
    
    for (Node child : children)
      encodeAST (out, child);
  }
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:33,代码来源:XdrAstCoding.java

示例15: getString

import org.apache.mina.filter.codec.ProtocolCodecException; //导入依赖的package包/类
/**
 * Read a length-delimited 4-byte-aligned UTF-8 string.
 */
public static String getString (ByteBuffer in)
  throws BufferUnderflowException, ProtocolCodecException
{
  try
  {
    int length = getPositiveInt (in);

    if (length == 0)
    {
      return "";
    } else
    {
      String string = in.getString (length, UTF8_DECODER.get ());
      
      in.skip (paddingFor (length));
      
      return string;
    }
  } catch (CharacterCodingException ex)
  {
    throw new ProtocolCodecException ("Invalid UTF-8 string", ex);
  }
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:27,代码来源:XdrCoding.java


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