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


Java ProtocolEncoderOutput類代碼示例

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


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

示例1: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws Exception
{
    ByteBuffer buffer = encoder.encodeMessage( ( Message ) message );

    IoBuffer ioBuffer = IoBuffer.wrap( buffer );

    if ( IS_DEBUG )
    {
        byte[] dumpBuffer = new byte[buffer.limit()];
        buffer.get( dumpBuffer );
        buffer.flip();
        CODEC_LOG.debug( "Encoded message \n " + message + "\n : " + Strings.dumpBytes( dumpBuffer ) );
    }

    out.write( ioBuffer );
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:21,代碼來源:LdapProtocolEncoder.java

示例2: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput output ) throws Exception
{
    final IoBuffer data = IoBuffer.allocate ( 0 );
    data.order ( ByteOrder.LITTLE_ENDIAN );
    data.setAutoExpand ( true );

    if ( message instanceof WriteRequestMessage )
    {
        encodeHeader ( data, (CommonMessage)message );
        encodeWriteRequest ( data, (WriteRequestMessage)message );
    }
    else if ( message instanceof CommonMessage )
    {
        encodeHeader ( data, (CommonMessage)message );
    }
    data.flip ();
    output.write ( data );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:20,代碼來源:ArduinoCodec.java

示例3: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput output ) throws Exception
{
    if ( ! ( message instanceof Frame ) )
    {
        throw new IllegalStateException ( String.format ( "Can only encode messages of type Frame but got %s", message.getClass () ) );
    }

    final Frame frame = (Frame)message;

    if ( logger.isTraceEnabled () )
    {
        logger.trace ( "Encode frame - type: {}, data: {}", frame.getType (), frame.getData () );
    }

    final IoBuffer buffer = IoBuffer.allocate ( 1 + 1 + 4 + frame.getData ().remaining () );
    buffer.put ( (byte)0x01 ); // version - #0
    buffer.put ( (byte)frame.getType ().ordinal () ); // frame type - #1
    buffer.putInt ( frame.getData ().remaining () ); // data size - #2
    buffer.put ( frame.getData () ); // data - #6
    buffer.flip ();

    output.write ( buffer );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:25,代碼來源:FrameEncoder.java

示例4: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
    if (!(message instanceof Serializable)) {
        throw new NotSerializableException();
    }

    IoBuffer buf = IoBuffer.allocate(64);
    buf.setAutoExpand(true);
    buf.putObject(message);

    int objectSize = buf.position() - 4;
    if (objectSize > maxObjectSize) {
        throw new IllegalArgumentException("The encoded object is too big: " + objectSize + " (> " + maxObjectSize
                + ')');
    }

    buf.flip();
    out.write(buf);
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:19,代碼來源:ObjectSerializationEncoder.java

示例5: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
    CharsetEncoder encoder = (CharsetEncoder) session.getAttribute(ENCODER);

    if (encoder == null) {
        encoder = charset.newEncoder();
        session.setAttribute(ENCODER, encoder);
    }

    String value = (message == null ? "" : message.toString());
    IoBuffer buf = IoBuffer.allocate(value.length()).setAutoExpand(true);
    buf.putString(value, encoder);

    if (buf.position() > maxLineLength) {
        throw new IllegalArgumentException("Line length: " + buf.position());
    }

    buf.putString(delimiter.getValue(), encoder);
    buf.flip();
    out.write(buf);
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:21,代碼來源:TextLineEncoder.java

示例6: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
@Override
public void encode(IoSession session, Object obj, ProtocolEncoderOutput out) throws Exception {
	TcpPacket packet = (TcpPacket) obj;
	byte[] byteData = packet.getByteData();
	int len = 18 + byteData.length;
	IoBuffer buf = IoBuffer.allocate(len);
	buf.put(HEAD);
	buf.putInt(len);
	buf.putInt(packet.gettOpCode());
	buf.putInt(packet.lockedId);
	buf.putInt(packet.unlockedId);
	buf.put(byteData);
	buf.flip();
	out.write(buf);

}
 
開發者ID:dianbaer,項目名稱:grain,代碼行數:17,代碼來源:MinaEncoder.java

示例7: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
@Override
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        final byte[] input = ((MaplePacket) message).getBytes();
        final byte[] unencrypted = new byte[input.length];
        System.arraycopy(input, 0, unencrypted, 0, input.length);

        final byte[] ret = new byte[unencrypted.length + 4];

        final byte[] header = client.getSendCrypto().getPacketHeader(unencrypted.length);
        synchronized(client.getSendCrypto()){
            MapleCustomEncryption.encryptData(unencrypted);
            client.getSendCrypto().crypt(unencrypted);

            System.arraycopy(header, 0, ret, 0, 4);
            System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length);

            final ByteBuffer out_buffer = ByteBuffer.wrap(ret);
            out.write(out_buffer);
        }
    } else { // no client object created yet, send unencrypted (hello)
            out.write(ByteBuffer.wrap(((MaplePacket) message).getBytes()));
    }
}
 
開發者ID:NoetherEmmy,項目名稱:intransigentms,代碼行數:27,代碼來源:MaplePacketEncoder.java

示例8: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
public void encode(IoSession session, Object message,
		ProtocolEncoderOutput out) throws Exception {
	if(!(message instanceof byte[])){
		throw new Exception("must send byte[]");
	}
	byte[] payload=(byte[]) message;
	ByteBuffer buf = ByteBuffer.allocate(payload.length, false);
       buf.put(payload);
       buf.flip();
       out.write(buf);
       if (isDebugEnabled)
       	LOGGER.debug(TairUtil.toHex(payload));
}
 
開發者ID:alibaba,項目名稱:tair-java-client,代碼行數:14,代碼來源:TairProtocolEncoder.java

示例9: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
@Override
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
   	if (genericClass.isInstance(message)) {
           byte[] datas = serializer.serialize(message);
           
           IoBuffer buffer = IoBuffer.allocate(256);
   		buffer.setAutoExpand(true);
   		buffer.setAutoShrink(true);
   		
   		buffer.putInt(datas.length);
   		buffer.put(datas);
   		
   		buffer.flip();
   		session.write(buffer);
       }
}
 
開發者ID:xuxueli,項目名稱:xxl-rpc,代碼行數:17,代碼來源:MinaEncoder.java

示例10: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
@Override
public void encode(IoSession session, byte[] message, ProtocolEncoderOutput out) throws Exception {
	try {
		IoBuffer buf = IoBuffer.allocate(1024);
		buf.setAutoExpand(true);
		int usedLen = 0;
		while (usedLen < message.length) {
			Packet pkg = Packet.PARSER.parseFrom(message, 0, message.length - usedLen);
			log.debug("Server FLUSH:" + pkg.toString());
			usedLen += pkg.toByteArray().length;
			buf.put(MessageCodec.makePkg(pkg.getCmdId(), pkg.toByteArray()));
		}

		buf.flip();
		out.write(buf);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:East196,項目名稱:maker,代碼行數:20,代碼來源:ProtobufMessageEncoder.java

示例11: getSendBuffer

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
/**
 * 同步處理要發送的數據。
 *
 * @param bytes
 * @return
 */
public void getSendBuffer(byte[] bytes, ProtocolEncoderOutput out,
		MapleClient client) {
	IoBuffer buffer = IoBuffer.allocate(bytes.length + 4, true);
	try {
		mutex.lock();

		buffer.put(getPacketHeader(bytes.length));
		buffer.put(bytes);
		buffer.position(buffer.position() - bytes.length);
		crypt(buffer, true);
		buffer.flip();
		// 建立完成待發送數據。
		out.write(buffer);
		out.flush();
	} finally {
		mutex.unlock();
	}
	buffer.free();
}
 
開發者ID:316181444,項目名稱:Hxms,代碼行數:26,代碼來源:MapleAESOFB.java

示例12: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
@Override
public void encode(IoSession session, Object message,
		ProtocolEncoderOutput out) throws Exception {
	try {
		byte compressedBytes[] = (byte[]) message;
		final IoBuffer buffer = IoBuffer.allocate(compressedBytes.length).setAutoExpand(true);
		
		buffer.put(compressedBytes);
		buffer.flip();
		out.write(buffer);
		WriteFuture wf = out.flush();
		wf.addListener(new IoFutureListener<IoFuture>() {
			@Override
			public void operationComplete(IoFuture future) {
				buffer.free();
			}
		});
		out.flush();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:myking520,項目名稱:gamefm,代碼行數:23,代碼來源:LuaEncoder.java

示例13: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
@Override
public void encode(IoSession is, Object o, ProtocolEncoderOutput peo) throws Exception {
    assert o instanceof RequestEnvelope;
    RequestEnvelope env = (RequestEnvelope) o;
    ByteArrayOutputStream bufOutStream = new ByteArrayOutputStream();
    ProtoWriter writer = new ProtoWriter(bufOutStream);
    if (env.ticket != null) {
        writer.put(CoreTags.TAG_SESSION_TICKET, env.ticket);
    }
    if (env.userName != null) {
        writer.put(CoreTags.TAG_USER_NAME, env.userName);
        writer.put(CoreTags.TAG_PASSWORD, env.password != null ? env.password : "");
    }
    PlatypusRequestWriter.write(env.request, writer);
    writer.flush();
    peo.write(IoBuffer.wrap(bufOutStream.toByteArray()));
}
 
開發者ID:marat-gainullin,項目名稱:platypus-js,代碼行數:18,代碼來源:RequestEncoder.java

示例14: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
@Override
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
    WebSocketConnection conn = (WebSocketConnection) session.getAttribute(Constants.CONNECTION);
    IoBuffer resultBuffer;
    if (message instanceof Packet) {
        Packet packet = (Packet) message;
        // if the connection is not native / direct, add websocket encoding
        resultBuffer = conn.isWebConnection() ? encodeOutgoingData(packet) : packet.getData();
    } else if (message instanceof HandshakeResponse) {
        HandshakeResponse resp = (HandshakeResponse) message;
        resultBuffer = resp.getResponse();
    } else if (message instanceof HandshakeRequest) {
        HandshakeRequest req = (HandshakeRequest) message;
        resultBuffer = req.getRequest();
    } else {
        throw new Exception("message not a websocket type");
    }
    out.write(resultBuffer);
}
 
開發者ID:Red5,項目名稱:red5-websocket,代碼行數:20,代碼來源:WebSocketEncoder.java

示例15: encode

import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入依賴的package包/類
/**
 * Check the id value and set it into context attachment.
 */
@Override
public void encode(IoSession session, Object msg, ProtocolEncoderOutput out) 
		throws Exception {
	
	/**
	 * If the message is already in IoBuffer format, 
	 * directly output it to client.
	 * 
	 * TODO Maybe used to optimize SessionMessage.
	 */
	if (msg instanceof IoBuffer) {
		out.write(msg);
	} else if ( msg instanceof XinqiMessage ) {
		XinqiMessage message = (XinqiMessage)msg;
		if (message != null) {
			IoBuffer body = encodeXinqiMessage(message);
			out.write(body);
		}
	}
}
 
開發者ID:wangqi,項目名稱:gameserver,代碼行數:24,代碼來源:ProtobufEncoder.java


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