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


Java Channels.write方法代碼示例

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


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

示例1: writeRequested

import org.jboss.netty.channel.Channels; //導入方法依賴的package包/類
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e)
		throws Exception {
	RpcRequest request = (RpcRequest) e.getMessage();
	ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
	//先寫入標示的魔數
	baos.write(Constants.MAGIC_BYTES);
	MySerializerFactory.getInstance(Constants.DEFAULT_RPC_CODE_MODE).encodeRequest(baos, request);
	ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(baos.toByteArray());
	Channels.write(ctx, e.getFuture(), buffer);
}
 
開發者ID:zhaoshiling1017,項目名稱:voyage,代碼行數:12,代碼來源:RpcRequestEncode.java

示例2: writeRequested

import org.jboss.netty.channel.Channels; //導入方法依賴的package包/類
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e)
		throws Exception {
	RpcResponse response = (RpcResponse) e.getMessage();
	ByteArrayOutputStream baos = new ByteArrayOutputStream(16384);
	//先寫入標示的魔數
	baos.write(Constants.MAGIC_BYTES);
	MySerializerFactory.getInstance(Constants.DEFAULT_RPC_CODE_MODE).encodeResponse(baos, response);
	ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(baos.toByteArray());
	Channels.write(ctx, e.getFuture(), buffer);
}
 
開發者ID:zhaoshiling1017,項目名稱:voyage,代碼行數:12,代碼來源:RpcResponseEncode.java

示例3: writeRequested

import org.jboss.netty.channel.Channels; //導入方法依賴的package包/類
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e)
		throws Exception {
	/* Create a newly ChannelBuffer */
	ChannelBuffer frmBuf = ChannelBuffers.dynamicBuffer();		
	/* Get a IMessage Object */
	IMessage sMsg = (IMessage) e.getMessage();
	/* Transfer the object to a byte array */
	byte[] frameContent = null;
			
	if((sMsg instanceof CPhotoUpdateMsg))
	{
		frmBuf.writeInt(1);
		frmBuf.writeInt(((CPhotoUpdateMsg)sMsg).getPhoto().length);
		frmBuf.writeInt(((CPhotoUpdateMsg)sMsg).getUserId());
		frmBuf.writeBytes(((CPhotoUpdateMsg)sMsg).getPhoto(), 0, ((CPhotoUpdateMsg)sMsg).getPhoto().length);
	}
	else
	{
		frameContent = sMsg.toString().getBytes(Config.PACKAGE_ENCODE);
		frmBuf.writeInt(0);
		/* Write the content length to the buffer */
		frmBuf.writeInt(frameContent.length);
		/* Write the content to the buffer */
		frmBuf.writeBytes(frameContent, 0, frameContent.length);
	}
			
	
	Channels.write(ctx, e.getFuture(), frmBuf);
}
 
開發者ID:qizhenghao,項目名稱:HiBangClient,代碼行數:31,代碼來源:PackageEncoder.java

示例4: handleDownstream

import org.jboss.netty.channel.Channels; //導入方法依賴的package包/類
public void handleDownstream(
          final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
      if (!(evt instanceof MessageEvent)) {
          ctx.sendDownstream(evt);
          return;
      }

      MessageEvent e = (MessageEvent) evt;
      
      if (e.getMessage() instanceof ChunkedInput) {
          ctx.sendDownstream(evt);
          return;
      }
      
      ChannelBufferOutputStream bout =
          new ChannelBufferOutputStream(dynamicBuffer(
                  estimatedLength, ctx.getChannel().getConfig().getBufferFactory()));
      bout.write(LENGTH_PLACEHOLDER);
      final CompactObjectOutputStream oout = new CompactObjectOutputStream(bout);
      try {
       oout.writeObject(e.getMessage());
       ExternalizeUtil.writeCollection(oout, oout.getReferences());
       oout.flush();
       oout.close();
      } catch (Throwable t) {
      	throw new FailedWriteException(e.getMessage(), t);
      }
      ChannelBuffer encoded = bout.buffer();
      encoded.setInt(0, encoded.writerIndex() - 4);
      write(ctx, e.getFuture(), encoded, e.getRemoteAddress());
for (InputStream is : oout.getStreams()) {
	Channels.write(ctx.getChannel(), new AnonymousChunkedStream(new BufferedInputStream(is, CHUNK_SIZE)));
}
  }
 
開發者ID:kenweezy,項目名稱:teiid,代碼行數:35,代碼來源:ObjectEncoder.java

示例5: flush

import org.jboss.netty.channel.Channels; //導入方法依賴的package包/類
@Override
public void flush() {
	this.dataOut = null;
	this.writer = null;
	Channels.write(this.ctx.getChannel(), null);
}
 
開發者ID:kenweezy,項目名稱:teiid,代碼行數:7,代碼來源:PgBackendProtocol.java

示例6: sendContents

import org.jboss.netty.channel.Channels; //導入方法依賴的package包/類
private void sendContents() {
	ChannelBuffer cb = this.dataOut;
	this.dataOut = null;
	this.writer = null;
	Channels.write(this.ctx, this.message.getFuture(), cb, this.message.getRemoteAddress());
}
 
開發者ID:kenweezy,項目名稱:teiid,代碼行數:7,代碼來源:PgBackendProtocol.java


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