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


Java ChannelBufferOutputStream.writeByte方法代碼示例

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


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

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

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

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

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