当前位置: 首页>>代码示例>>Java>>正文


Java ChannelBufferOutputStream.write方法代码示例

本文整理汇总了Java中org.jboss.netty.buffer.ChannelBufferOutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelBufferOutputStream.write方法的具体用法?Java ChannelBufferOutputStream.write怎么用?Java ChannelBufferOutputStream.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.netty.buffer.ChannelBufferOutputStream的用法示例。


在下文中一共展示了ChannelBufferOutputStream.write方法的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: 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

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

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

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

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

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

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

示例10: setCompressedImage

import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
private void setCompressedImage(Mat inputFrame, tms_ss_rcnn.obj_detectionRequest request) throws IOException {
    Time time = mConnectedNode.getCurrentTime();
    request.getImage().getHeader().setStamp(time);
    request.getImage().getHeader().setFrameId("ObjectDetection");
    request.getImage().getHeader().setSeq(sequenceNumber++);
    request.getImage().setFormat("jpg");

    MatOfByte buf = new MatOfByte();
    Highgui.imencode(".jpg", inputFrame, buf);
    ChannelBufferOutputStream stream = new ChannelBufferOutputStream(MessageBuffers.dynamicBuffer());
    stream.write(buf.toArray());

    request.getImage().setData(stream.buffer().copy());
}
 
开发者ID:kazuto1011,项目名称:ros-tms-perception,代码行数:15,代码来源:ObjectDetectionClient.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: 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());
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:23,代码来源:MessageBatch.java

示例13: encodeToChannelBuffer

import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
public ChannelBuffer encodeToChannelBuffer(Message message) throws IOException {
    byte[] messageBytes = encodeMessage(message);
    byte[] headerBytes = encodeHeader(messageBytes);

    ChannelBuffer cb = ChannelBuffers.buffer(2 + headerBytes.length + 1 + messageBytes.length);
    ChannelBufferOutputStream cbos = new ChannelBufferOutputStream(cb);
    cbos.writeByte(RECORD_SEPARATOR);
    cbos.writeByte(headerBytes.length);
    cbos.write(headerBytes);
    cbos.writeByte(UNIT_SEPARATOR);
    cbos.write(messageBytes);

    return cb;
}
 
开发者ID:nickman,项目名称:heka-java,代码行数:15,代码来源:Encoder.java

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

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


注:本文中的org.jboss.netty.buffer.ChannelBufferOutputStream.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。