本文整理匯總了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());
}