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


Java ChannelBufferOutputStream.buffer方法代碼示例

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


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

示例1: 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

示例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);
	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

示例3: 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

示例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:kkllwww007,項目名稱:jstrom,代碼行數:23,代碼來源:MessageBatch.java

示例5: 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

示例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;
    }

    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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: handleDownstream

import org.jboss.netty.buffer.ChannelBufferOutputStream; //導入方法依賴的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

示例12: 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 (TaskMessage msg : msgs)
        writeTaskMessage(bout, msg);

    //add a END_OF_BATCH indicator
    ControlMessage.EOB_MESSAGE.write(bout);

    bout.close();

    return bout.buffer();
}
 
開發者ID:metamx,項目名稱:incubator-storm,代碼行數:17,代碼來源:MessageBatch.java

示例13: encode

import org.jboss.netty.buffer.ChannelBufferOutputStream; //導入方法依賴的package包/類
@Override
protected Object encode(ChannelHandlerContext ctx,
                        Channel channel, Object msg) throws Exception {
  if (!(msg instanceof WritableRequest)) {
    throw new IllegalArgumentException(
        "encode: Got a message of type " + msg.getClass());
  }

  // Encode the request
  if (LOG.isDebugEnabled()) {
    startEncodingNanoseconds = TIME.getNanoseconds();
  }
  WritableRequest writableRequest = (WritableRequest) msg;
  int requestSize = writableRequest.getSerializedSize();
  ChannelBuffer channelBuffer;
  if (requestSize == WritableRequest.UNKNOWN_SIZE) {
    channelBuffer = ChannelBuffers.dynamicBuffer(
        bufferStartingSize,
        ctx.getChannel().getConfig().getBufferFactory());
  } else {
    requestSize += LENGTH_PLACEHOLDER.length + 1;
    channelBuffer = useDirectBuffers ?
        ChannelBuffers.directBuffer(requestSize) :
        ChannelBuffers.buffer(requestSize);
  }
  ChannelBufferOutputStream outputStream =
      new ChannelBufferOutputStream(channelBuffer);
  outputStream.write(LENGTH_PLACEHOLDER);
  outputStream.writeByte(writableRequest.getType().ordinal());
  try {
    writableRequest.write(outputStream);
  } catch (IndexOutOfBoundsException e) {
    LOG.error("encode: Most likely the size of request was not properly " +
        "specified - see getSerializedSize() in " +
        writableRequest.getType().getRequestClass());
    throw new IllegalStateException(e);
  }
  outputStream.flush();
  outputStream.close();

  // Set the correct size at the end
  ChannelBuffer encodedBuffer = outputStream.buffer();
  encodedBuffer.setInt(0, encodedBuffer.writerIndex() - 4);
  if (LOG.isDebugEnabled()) {
    LOG.debug("encode: Client " + writableRequest.getClientId() + ", " +
        "requestId " + writableRequest.getRequestId() +
        ", size = " + encodedBuffer.writerIndex() + ", " +
        writableRequest.getType() + " took " +
        Times.getNanosSince(TIME, startEncodingNanoseconds) + " ns");
  }
  return encodedBuffer;
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:53,代碼來源:RequestEncoder.java

示例14: encode

import org.jboss.netty.buffer.ChannelBufferOutputStream; //導入方法依賴的package包/類
@Override
  protected Object encode(ChannelHandlerContext ctx,
      Channel channel, Object msg) throws Exception {
    if (LOG.isDebugEnabled()) {
      LOG.debug("encode(" + ctx + "," + channel + "," + msg);
    }

    if (!(msg instanceof WritableRequest)) {
      throw new IllegalArgumentException(
          "encode: cannot encode message of type " + msg.getClass() +
              " since it is not an instance of an implementation of " +
              " WritableRequest.");
    }
    @SuppressWarnings("unchecked")
    WritableRequest writableRequest =
      (WritableRequest) msg;
    ChannelBufferOutputStream outputStream =
      new ChannelBufferOutputStream(ChannelBuffers.dynamicBuffer(
        10, ctx.getChannel().getConfig().getBufferFactory()));

    if (LOG.isDebugEnabled()) {
      LOG.debug("encode: Encoding a message of type " + msg.getClass());
    }
    outputStream.write(LENGTH_PLACEHOLDER);

    // write type of object.
    outputStream.writeByte(writableRequest.getType().ordinal());

    // write the object itself.
    writableRequest.write(outputStream);

    outputStream.flush();

    // Set the correct size at the end.
    ChannelBuffer encodedBuffer = outputStream.buffer();
    encodedBuffer.setInt(0, encodedBuffer.writerIndex() - 4);

    if (LOG.isDebugEnabled()) {
      LOG.debug("encode: Encoding a message of type " + msg.getClass());
    }
/*if[HADOOP_NON_SECURE]
else[HADOOP_NON_SECURE]*/
    if (writableRequest.getType() == RequestType.SASL_COMPLETE_REQUEST) {
      // We are sending to the client a SASL_COMPLETE response (created by
      // the SaslServer handler). The SaslServer handler has removed itself
      // from the pipeline after creating this response, and now it's time for
      // the ResponseEncoder to remove itself also.
      if (LOG.isDebugEnabled()) {
        LOG.debug("encode: Removing RequestEncoder handler: no longer needed," +
            " since client: " + ctx.getChannel().getRemoteAddress() + " has " +
            "completed authenticating.");
      }
      ctx.getPipeline().remove(this);
    }
/*end[HADOOP_NON_SECURE]*/
    return encodedBuffer;
  }
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:58,代碼來源:ResponseEncoder.java

示例15: encode

import org.jboss.netty.buffer.ChannelBufferOutputStream; //導入方法依賴的package包/類
@Override
protected Object encode(ChannelHandlerContext ctx,
    Channel channel, Object msg) throws Exception {
  if (LOG.isDebugEnabled()) {
    LOG.debug("encode(" + ctx + "," + channel + "," + msg);
  }

  if (!(msg instanceof WritableRequest)) {
    throw new IllegalArgumentException(
        "encode: cannot encode message of type " + msg.getClass() +
            " since it is not an instance of an implementation of " +
            " WritableRequest.");
  }
  @SuppressWarnings("unchecked")
  WritableRequest writableRequest =
    (WritableRequest) msg;
  ChannelBufferOutputStream outputStream =
    new ChannelBufferOutputStream(ChannelBuffers.dynamicBuffer(
      10, ctx.getChannel().getConfig().getBufferFactory()));

  if (LOG.isDebugEnabled()) {
    LOG.debug("encode: Encoding a message of type " + msg.getClass());
  }
  outputStream.write(LENGTH_PLACEHOLDER);

  // write type of object.
  outputStream.writeByte(writableRequest.getType().ordinal());

  // write the object itself.
  writableRequest.write(outputStream);

  outputStream.flush();

  // Set the correct size at the end.
  ChannelBuffer encodedBuffer = outputStream.buffer();
  encodedBuffer.setInt(0, encodedBuffer.writerIndex() - 4);

  if (LOG.isDebugEnabled()) {
    LOG.debug("encode: Encoding a message of type " + msg.getClass());
  }


  if (writableRequest.getType() == RequestType.SASL_COMPLETE_REQUEST) {
    // We are sending to the client a SASL_COMPLETE response (created by
    // the SaslServer handler). The SaslServer handler has removed itself
    // from the pipeline after creating this response, and now it's time for
    // the ResponseEncoder to remove itself also.
    if (LOG.isDebugEnabled()) {
      LOG.debug("encode: Removing RequestEncoder handler: no longer needed," +
          " since client: " + ctx.getChannel().getRemoteAddress() + " has " +
          "completed authenticating.");
    }
    ctx.getPipeline().remove(this);
  }

  return encodedBuffer;
}
 
開發者ID:zfighter,項目名稱:giraph-research,代碼行數:58,代碼來源:ResponseEncoder.java


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