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


Java ProtocolDecoderOutput.write方法代碼示例

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


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

示例1: decode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws Exception
{
    @SuppressWarnings("unchecked")
    LdapMessageContainer<MessageDecorator<? extends Message>> messageContainer =
        ( LdapMessageContainer<MessageDecorator<? extends Message>> )
        session.getAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR );

    if ( session.containsAttribute( LdapDecoder.MAX_PDU_SIZE_ATTR ) )
    {
        int maxPDUSize = ( Integer ) session.getAttribute( LdapDecoder.MAX_PDU_SIZE_ATTR );

        messageContainer.setMaxPDUSize( maxPDUSize );
    }

    List<Message> decodedMessages = new ArrayList<>();
    ByteBuffer buf = in.buf();

    decode( buf, messageContainer, decodedMessages );

    for ( Message message : decodedMessages )
    {
        out.write( message );
    }
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:29,代碼來源:LdapProtocolDecoder.java

示例2: processWriteResult

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的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

示例3: processDataUpdate

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的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

示例4: processBrowseAdded

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的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

示例5: processHello

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的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

示例6: doDecode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    if (in.prefixedDataAvailable(2)) {
        short length = in.getShort();//獲取包長

        byte[] bytes = new byte[length];
        in.get(bytes);
        byte[] msgidBytes = new byte[Constants.COMMAND_LENGTH];
        System.arraycopy(bytes, 0, msgidBytes, 0, Constants.COMMAND_LENGTH);
        int msgid = NumberUtils.bytesToInt(msgidBytes);
        if (msgid != 0) {
            //通過工廠方法生成指定消息類型的指令對象
            BaseCommand command = CommandFactory.createCommand(msgid);

            byte[] cmdBodyBytes = new byte[length - Constants.COMMAND_LENGTH];
            System.arraycopy(bytes, Constants.COMMAND_LENGTH, cmdBodyBytes, 0, length - Constants.COMMAND_LENGTH);
            command.bodyFromBytes(cmdBodyBytes);
            out.write(command);
            return true;
        }
    }

    return false;
}
 
開發者ID:Keybo1013,項目名稱:mina,代碼行數:25,代碼來源:CommandDecoder.java

示例7: doDecode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
@Override
  public boolean doDecode(IoSession session, IoBuffer in,
          ProtocolDecoderOutput out) throws Exception {
      // log.debug("doDecode(...)...");

      XMLLightweightParser parser = (XMLLightweightParser) session
              .getAttribute(XmppIoHandler.XML_PARSER);
      parser.read(in);

// 如果有消息
      if (parser.areThereMsgs()) {
          for (String stanza : parser.getMsgs()) {
              out.write(stanza);
          }
      }
      
// 是否還有剩餘
      return !in.hasRemaining();
  }
 
開發者ID:lijian17,項目名稱:androidpn-server,代碼行數:20,代碼來源:XmppDecoder.java

示例8: getDecoder

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
@Override
public ProtocolDecoder getDecoder(IoSession is) throws Exception {
    return new CumulativeProtocolDecoder() {

        protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
            if (in.remaining() > 0) {
                byte[] buf = new byte[in.remaining()];
                in.get(buf);
                out.write(new String(buf, "US-ASCII"));
                return true;
            } else {
                return false;
            }
        }
    };
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:Mina2VMCustomCodecTest.java

示例9: decode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
@Override
public void decode(IoSession ioSession, IoBuffer ioBuffer, ProtocolDecoderOutput out) throws Exception
{
    byte[] message = new byte[ioBuffer.limit()];

    ioBuffer.get(message);

    UltravoxMessage ultravoxMessage = UltravoxMessageFactory.getMessage(message);

    if(ultravoxMessage != null)
    {
        out.write(ultravoxMessage);
    }
    else
    {
        out.write(message);
    }
}
 
開發者ID:DSheirer,項目名稱:sdrtrunk,代碼行數:19,代碼來源:UltravoxDecoder.java

示例10: doDecode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
@Override
protected boolean doDecode(IoSession is, IoBuffer ib, ProtocolDecoderOutput pdo) throws Exception {
    synchronized (is) {
        final MessageCodec stats = getSessionCodec(is);
        // 消息
        SessionMessage message = null;
        // 消息不等於空,循環讀取消息
        do {
            message = stats.readMessage(is, ib);
            if (message != null) {
                pdo.write(message);
            }
        } while (message != null);
        // 調試輸出
        // System.out.println(ib);
        return message != null;
    }
}
 
開發者ID:316181444,項目名稱:GameServerFramework,代碼行數:19,代碼來源:MessageDecoder.java

示例11: doDecode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
	RedisProtocolParser parser = (RedisProtocolParser) session.getAttribute(REDIS_PROTOCOL_PARSER);
	// 將接收到的數據通過解析器解析為Redis數據包對象
	parser.read(in.buf());

	// 獲取解析器解析出的數據包
	RedisPacket[] redisPackets = parser.getPackets();
	if (redisPackets != null) {
		for (RedisPacket redisPacket : redisPackets) {
			out.write(redisPacket);
		}
	}

	// 以是否讀取完數據為判斷符
	return !in.hasRemaining();
}
 
開發者ID:wmz7year,項目名稱:Redis-Synyed,代碼行數:18,代碼來源:RedisProtocolDecoder.java

示例12: doDecode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {

	if (in.remaining() < 4) {
        return false;
    }
	in.mark();	// mark 2 reset, reset call rollback to mark place
	
    int dataLength = in.getInt();	// data length
    if (dataLength < in.remaining()) {
        return false;
    }
    if (dataLength > in.remaining()) {
        in.reset();
    }
    
    byte[] datas = new byte[dataLength];	// data
    in.get(datas, 0, dataLength);
    
    Object obj = serializer.deserialize(datas, genericClass);
    out.write(obj);
	return true;
}
 
開發者ID:xuxueli,項目名稱:xxl-rpc,代碼行數:24,代碼來源:MinaDecoder.java

示例13: decode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
/**
 * 解碼並處理斷包
 */
@Override
public MessageDecoderResult decode(IoSession session, IoBuffer buffer, ProtocolDecoderOutput output)
		throws Exception {
	int nRemainning = buffer.remaining();
	if (nRemainning < MessageCodec.HEAD_LENGTH) {// min length
		return MessageDecoderResult.NEED_DATA;
	} else {
		buffer.mark();// 標記位置mark=pos
		int nLen = buffer.getShort();// 包長(包括消息頭)
		buffer.reset();// 重置位置pos=mark

		// 如果buffer中可讀的長度小於包長說明斷包返回 NEED_DATA
		if (nRemainning < nLen) {
			// buffer.reset();//重置位置pos=mark
			return MessageDecoderResult.NEED_DATA;
		}
		// buffer.reset();//重置位置pos=mark
	}

	Object proObj = decodeBody(session, buffer);
	output.write(proObj);// 解碼後輸出
	return MessageDecoderResult.OK;
}
 
開發者ID:East196,項目名稱:maker,代碼行數:27,代碼來源:ProtobufMessageDecoder.java

示例14: doDecode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
@Override
protected final boolean doDecode(IoSession session, IoBuffer buf, ProtocolDecoderOutput out) throws Exception {
	/*byte cmd = buf.get();
	byte error = buf.get();
	byte b1 = buf.get();
	byte b2 = buf.get();
	short packetLength = (short) (b2 & 0xFF << 8 | b1 & 0xFF);
	int length = buf.remaining();
	if (packetLength >= length) {
		byte[] in = new byte[packetLength + 4];
		in[0] = cmd;
		in[1] = error;
		in[2] = b1;
		in[3] = b2;
		buf.get(in, 4, packetLength);
		out.write(in);
		return true;
	}
	return false;*/
	int length = buf.remaining();
	byte[] input = new byte[length];
	buf.get(input, 0, length);
	out.write(input);
	return true;
}
 
開發者ID:JavaWoW,項目名稱:JavaWoW,代碼行數:26,代碼來源:AuthDecoder.java

示例15: doDecode

import org.apache.mina.filter.codec.ProtocolDecoderOutput; //導入方法依賴的package包/類
@Override
public boolean doDecode(IoSession session, IoBuffer in,
        ProtocolDecoderOutput out) throws Exception {
    log.debug("doDecode(...)...");

    // Get the XML light parser from the IoSession
    XMLLightweightParser parser = (XMLLightweightParser) session
            .getAttribute("XML-PARSER");
    // Parse as many stanzas as possible from the received data
    parser.read(in);

    if (parser.areThereMsgs()) {
        for (String stanza : parser.getMsgs()) {
            out.write(stanza);
        }
    }
    return !in.hasRemaining();
}
 
開發者ID:elphinkuo,項目名稱:Androidpn,代碼行數:19,代碼來源:XmppDecoder.java


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