本文整理汇总了Java中org.jboss.netty.buffer.ChannelBufferOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java ChannelBufferOutputStream类的具体用法?Java ChannelBufferOutputStream怎么用?Java ChannelBufferOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChannelBufferOutputStream类属于org.jboss.netty.buffer包,在下文中一共展示了ChannelBufferOutputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: encode
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object message) throws Exception {
if (message instanceof SyncMessage) {
ChannelBuffer buf = new DynamicChannelBuffer(512);
ChannelBufferOutputStream os = new ChannelBufferOutputStream(buf);
TCompactProtocol thriftProtocol =
new TCompactProtocol(new TIOStreamTransport(os));
((SyncMessage) message).write(thriftProtocol);
ChannelBuffer len = ChannelBuffers.buffer(4);
len.writeInt(buf.readableBytes());
return ChannelBuffers.wrappedBuffer(len, buf);
}
return message;
}
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:17,代码来源:ThriftFrameEncoder.java
示例2: encode
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object msg) throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(
dynamicBuffer(1024, ctx.getChannel().getConfig()
.getBufferFactory()));
bout.write(LENGTH_PLACEHOLDER);
Hessian2Output h2o = new Hessian2Output(bout);
try {
h2o.writeObject(msg);
h2o.flush();
} finally {
h2o.close();
}
ChannelBuffer encoded = bout.buffer();
encoded.setInt(0, encoded.writerIndex() - 4);
return encoded;
}
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:19,代码来源:HessianEncoder.java
示例3: encode
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object msg) throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(
dynamicBuffer(1024, ctx.getChannel().getConfig()
.getBufferFactory()));
bout.write(LENGTH_PLACEHOLDER);
JBossObjectOutputStream oout = new JBossObjectOutputStream(bout);
try {
oout.writeObject(msg);
oout.flush();
} finally {
oout.close();
}
ChannelBuffer encoded = bout.buffer();
encoded.setInt(0, encoded.writerIndex() - 4);
return encoded;
}
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:19,代码来源:JBossSerializationEncoder.java
示例4: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
ChannelBuffer buffer() throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(
ChannelBuffers.directBuffer(encoded_length));
for (Object msg : msgs)
if (msg instanceof TaskMessage)
writeTaskMessage(bout, (TaskMessage) msg);
else {
// LOG.debug("Write one non-TaskMessage {}", msg );
((ControlMessage) msg).write(bout);
}
// add a END_OF_BATCH indicator
ControlMessage.EOB_MESSAGE.write(bout);
// LOG.debug("ControlMessage.EOB_MESSAGE " );
bout.close();
return bout.buffer();
}
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:24,代码来源:MessageBatch.java
示例5: writeTaskMessage
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
/**
* write a TaskMessage into a stream
*
* Each TaskMessage is encoded as: task ... short(2) len ... int(4) payload
* ... byte[] *
*/
private void writeTaskMessage(ChannelBufferOutputStream bout,
TaskMessage message) throws Exception {
int payload_len = 0;
if (message.message() != null)
payload_len = message.message().length;
int task_id = message.task();
if (task_id > Short.MAX_VALUE)
throw new RuntimeException("Task ID should not exceed "
+ Short.MAX_VALUE);
bout.writeShort((short) task_id);
bout.writeInt(payload_len);
if (payload_len > 0)
bout.write(message.message());
// @@@ TESTING CODE
// LOG.info("Write one message taskid:{}, len:{}, data:{}", task_id
// , payload_len, JStormUtils.toPrintableString(message.message()) );
}
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:27,代码来源:MessageBatch.java
示例6: encode
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
{
if (!(msg instanceof ChannelBuffer))
{
return msg;
}
ChannelBuffer body = (ChannelBuffer) msg;
int length = body.readableBytes();
ChannelBuffer header = channel.getConfig().getBufferFactory()
.getBuffer(body.order(), CodedOutputStream.computeRawVarint64Size(length) + 4);
CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(new ChannelBufferOutputStream(header));
codedOutputStream.writeRawVarint64(length);
int value = 0x0;
value |= (0x0 & 0xff);// network version
value |= ((0x0 & 0xff) << 8);// type
if (ctx.getPipeline().get("cryptoEncoder") != null) value |= ((0x1 & 0xf) << 16);// crypto type
else value |= ((0x0 & 0xf) << 16);// crypto type
value |= ((0x0 & 0xfff) << 20);// version
codedOutputStream.writeRawLittleEndian32(value);
codedOutputStream.flush();
return wrappedBuffer(header, body);
}
开发者ID:mornsun,项目名称:bdclient,代码行数:25,代码来源:ProtobufVarint64LengthFieldPrepender.java
示例7: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
ChannelBuffer buffer() throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encoded_length));
for (Object msg : msgs)
if (msg instanceof TaskMessage)
writeTaskMessage(bout, (TaskMessage) msg);
else {
// LOG.debug("Write one non-TaskMessage {}", msg );
((ControlMessage) msg).write(bout);
}
// add a END_OF_BATCH indicator
ControlMessage.EOB_MESSAGE.write(bout);
// LOG.debug("ControlMessage.EOB_MESSAGE " );
bout.close();
return bout.buffer();
}
开发者ID:kkllwww007,项目名称:jstrom,代码行数:23,代码来源:MessageBatch.java
示例8: writeTaskMessage
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
/**
* write a TaskMessage into a stream
*
* Each TaskMessage is encoded as: task ... short(2) len ... int(4) payload ... byte[] *
*/
private void writeTaskMessage(ChannelBufferOutputStream bout, TaskMessage message) throws Exception {
int payload_len = 0;
if (message.message() != null)
payload_len = message.message().length;
int task_id = message.task();
if (task_id > Short.MAX_VALUE)
throw new RuntimeException("Task ID should not exceed " + Short.MAX_VALUE);
bout.writeShort((short) task_id);
bout.writeInt(payload_len);
if (payload_len > 0)
bout.write(message.message());
// @@@ TESTING CODE
// LOG.info("Write one message taskid:{}, len:{}, data:{}", task_id
// , payload_len, JStormUtils.toPrintableString(message.message()) );
}
开发者ID:kkllwww007,项目名称:jstrom,代码行数:24,代码来源:MessageBatch.java
示例9: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
ChannelBuffer buffer() throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encoded_length));
for (Object msg : msgs)
if (msg instanceof TaskMessage)
writeTaskMessage(bout, (TaskMessage)msg);
else
((ControlMessage)msg).write(bout);
//add a END_OF_BATCH indicator
ControlMessage.EOB_MESSAGE.write(bout);
bout.close();
return bout.buffer();
}
开发者ID:troyding,项目名称:storm-resa,代码行数:20,代码来源:MessageBatch.java
示例10: writeResponse
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
private void writeResponse(MessageEvent e) {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
ChannelBuffer content = ChannelBuffers.dynamicBuffer();
Writer writer = new OutputStreamWriter(new ChannelBufferOutputStream(content), CharsetUtil.UTF_8);
reportAdapter.toJson(report.get(), writer);
try {
writer.close();
} catch (IOException e1) {
LOG.error("error writing resource report", e1);
}
response.setContent(content);
ChannelFuture future = e.getChannel().write(response);
future.addListener(ChannelFutureListener.CLOSE);
}
开发者ID:chtyim,项目名称:incubator-twill,代码行数:17,代码来源:TrackerService.java
示例11: encode
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object msg) throws Exception {
if (msg instanceof ChannelBuffer) {
return msg;
}
ChannelBufferOutputStream out = new ChannelBufferOutputStream(
ChannelBuffers.dynamicBuffer(estimatedLength, ctx.getChannel()
.getConfig().getBufferFactory()));
// MessagePack.pack(out, msg);
messagePack.write(out, msg);
ChannelBuffer result = out.buffer();
return result;
}
开发者ID:nict-wisdom,项目名称:rasc,代码行数:18,代码来源:MessagePackEncoder.java
示例12: invalidRequestSent
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
public void invalidRequestSent(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
Channel channel = ctx.getChannel();
if (channel == null || !channel.isOpen()) {
log.debug("Not writing any response, channel is already closed.", e.getCause());
return;
}
final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.BAD_REQUEST);
response.headers().add(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
response.headers().add(HttpHeaders.Names.CONNECTION, "close");
final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
new ChannelBufferOutputStream(buffer).writeBytes("Your client has sent a malformed or illegal request.\n");
response.setContent(buffer);
final ChannelFuture channelFuture = channel.write(response);
channelFuture.addListener(ChannelFutureListener.CLOSE);
}
开发者ID:graylog-labs,项目名称:jersey-netty,代码行数:19,代码来源:NettyContainer.java
示例13: encode
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
@Override
protected Object encode(final ChannelHandlerContext ctx, final Channel channel, final Object msg) throws IOException {
if (msg instanceof ResponseObject) {
final ChannelBuffer result = ChannelBuffers.dynamicBuffer(DEFAULT_BUFFER_SIZE);
final ChannelBufferOutputStream out = new ChannelBufferOutputStream(result);
((ResponseObject) msg).writeTo(out);
out.write(OBJECT_TERMINATOR);
return result;
} else if (msg instanceof Message) {
return ChannelBuffers.wrappedBuffer(msg.toString().getBytes(Charsets.UTF_8), OBJECT_TERMINATOR);
}
return msg;
}
开发者ID:RIPE-NCC,项目名称:whois,代码行数:17,代码来源:WhoisEncoder.java
示例14: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
@Override
public ChannelBuffer buffer() throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encodedLength));
for (Object msg : msgs)
if (msg instanceof TaskMessage)
writeTaskMessage(bout, (TaskMessage) msg);
else {
// LOG.debug("Write one non-TaskMessage {}", msg );
((ControlMessage) msg).write(bout);
}
// add a END_OF_BATCH indicator
ControlMessage.EOB_MESSAGE.write(bout);
// LOG.debug("ControlMessage.EOB_MESSAGE " );
bout.close();
return bout.buffer();
}
开发者ID:alibaba,项目名称:jstorm,代码行数:24,代码来源:MessageBatch.java
示例15: writeTaskMessage
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
/**
* write a TaskMessage into a stream
*
* Each TaskMessage is encoded as: task ... short(2) len ... int(4) payload ... byte[] *
*/
private void writeTaskMessage(ChannelBufferOutputStream bout, TaskMessage message) throws Exception {
int payload_len = 0;
if (message.message() != null)
payload_len = message.message().length;
short type = message.get_type();
bout.writeShort(type);
int task_id = message.task();
if (task_id > Short.MAX_VALUE)
throw new RuntimeException("Task ID should not exceed " + Short.MAX_VALUE);
bout.writeShort((short) task_id);
bout.writeInt(payload_len);
if (payload_len > 0)
bout.write(message.message());
// LOG.info("Write one message taskid:{}, len:{}, data:{}", taskId
// , payload_len, JStormUtils.toPrintableString(message.message()) );
}
开发者ID:alibaba,项目名称:jstorm,代码行数:26,代码来源:MessageBatch.java
示例16: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
@Override
public ChannelBuffer buffer() throws Exception {
int payloadLen = 0;
if (_message != null)
payloadLen = _message.length;
int totalLen = 8 + payloadLen;
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(totalLen));
bout.writeShort(_type);
if (_task > Short.MAX_VALUE)
throw new RuntimeException("Task ID should not exceed " + Short.MAX_VALUE);
bout.writeShort((short) _task);
bout.writeInt(payloadLen);
if (payloadLen > 0)
bout.write(_message);
bout.close();
return bout.buffer();
}
开发者ID:alibaba,项目名称:jstorm,代码行数:25,代码来源:TaskMessage.java
示例17: generateData
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
@Override
public ChannelBuffer generateData() {
ChannelBufferOutputStream output = new ChannelBufferOutputStream(MessageBuffers.dynamicBuffer());
try {
output.write(new byte[WIDTH * HEIGHT]);
} catch (Exception e) {
throw new RuntimeException("Empty map generator generateData error: " + e.getMessage());
}
return output.buffer();
}
开发者ID:ekumenlabs,项目名称:tangobot,代码行数:11,代码来源:EmptyMapGenerator.java
示例18: doEncode
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
private Object doEncode(Request request, ChannelHandlerContext ctx, Channel channel) throws Exception {
//version from request header;
byte ver = request.getHeader().getSerializeVersion();
//overwrite if request header == 0 and version != 0, use version
if ( ver == 0 && version != 0)
ver = version;
int pLen = request.getPayload() == null ? 0 : request.getPayload().length;
byte[] header = request.getHeader().toByte();
// encoding length , and check the max value of integer, should be 2GB
int len = TOTAL + header.length + pLen + R_SIZE;
if ( len > Integer.MAX_VALUE ) {
channel.close();
throw new Exception( len+" exceeding Integer.MAX_VALUE");
}
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(dynamicBuffer(
len, ctx.getChannel().getConfig().getBufferFactory()));
bout.write(SIGNATURE);
bout.write(ver);
bout.writeInt(len);
bout.writeShort((short) header.length);
bout.write(header);
// request type
bout.write((byte) request.getType().ordinal());
bout.write( request.getPayload());
bout.flush();
bout.close();
ChannelBuffer encoded = bout.buffer();
return encoded;
}
开发者ID:viant,项目名称:CacheStore,代码行数:30,代码来源:Encoder.java
示例19: handleDownstream
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
/** Serialize outgoing NithPoints messages passing downstream in the channel. */
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
if (!(evt instanceof MessageEvent)) {
ctx.sendDownstream(evt);
return;
}
MessageEvent e = (MessageEvent) evt;
Message message = (Message)e.getMessage();
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
serializer.serialize(message, new ChannelBufferOutputStream(buffer));
write(ctx, e.getFuture(), buffer, e.getRemoteAddress());
}
开发者ID:appteam-nith,项目名称:NithPointsj,代码行数:15,代码来源:TCPNetworkConnection.java
示例20: CompressedImagePublisher
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入依赖的package包/类
public CompressedImagePublisher(ConnectedNode connectedNode) {
this.connectedNode = connectedNode;
NameResolver resolver = connectedNode.getResolver().newChild("camera");
imagePublisher =
connectedNode.newPublisher(resolver.resolve("image/compressed"),
sensor_msgs.CompressedImage._TYPE);
cameraInfoPublisher =
connectedNode.newPublisher(resolver.resolve("camera_info"), sensor_msgs.CameraInfo._TYPE);
stream = new ChannelBufferOutputStream(MessageBuffers.dynamicBuffer());
}
开发者ID:frankjoshua,项目名称:AndroidRosJava,代码行数:11,代码来源:CompressedImagePublisher.java
注:本文中的org.jboss.netty.buffer.ChannelBufferOutputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论