本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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)));
}
}
示例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);
}
示例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());
}