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


Java ChannelBufferOutputStream類代碼示例

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


ChannelBufferOutputStream類屬於org.jboss.netty.buffer包,在下文中一共展示了ChannelBufferOutputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


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