org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf.writeBytes()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf.writeBytes()方法的一些代码示例,展示了ByteBuf.writeBytes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.writeBytes()方法的具体详情如下:
包路径:org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:writeBytes

ByteBuf.writeBytes介绍

暂无

代码示例

代码示例来源:origin: apache/flink

/**
 * Helper for serializing the messages.
 *
 * @param alloc            The {@link ByteBufAllocator} used to allocate the buffer to serialize the message into.
 * @param requestId        The id of the request to which the message refers to.
 * @param messageType    The {@link MessageType type of the message}.
 * @param payload        The serialized version of the message.
 * @return A {@link ByteBuf} containing the serialized message.
 */
private static ByteBuf writePayload(
    final ByteBufAllocator alloc,
    final long requestId,
    final MessageType messageType,
    final byte[] payload) {
  final int frameLength = HEADER_LENGTH + REQUEST_ID_SIZE + payload.length;
  final ByteBuf buf = alloc.ioBuffer(frameLength + Integer.BYTES);
  buf.writeInt(frameLength);
  writeHeader(buf, messageType);
  buf.writeLong(requestId);
  buf.writeBytes(payload);
  return buf;
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

/**
 * Copies bytes from the src to dest, but do not exceed the capacity of the dest buffer.
 *
 * @param src The ByteBuf to copy bytes from.
 * @param dest The ByteBuf to copy bytes to.
 * @param maxCopySize Maximum size of bytes to copy.
 * @return The length of actually copied bytes.
 */
private int copyToTargetBuffer(ByteBuf src, ByteBuf dest, int maxCopySize) {
  int copyLength = Math.min(src.readableBytes(), maxCopySize);
  checkState(dest.writableBytes() >= copyLength,
    "There is not enough space to copy " + copyLength + " bytes, writable = " + dest.writableBytes());
  dest.writeBytes(src, copyLength);
  return copyLength;
}

代码示例来源:origin: org.apache.flink/flink-runtime

@Override
public ByteBuf copy(int index, int length) {
  checkIndex(index, length);
  ByteBuf copy = alloc().buffer(length, maxCapacity());
  copy.writeBytes(this, index, length);
  return copy;
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

@Override
public ByteBuf copy(int index, int length) {
  checkIndex(index, length);
  ByteBuf copy = alloc().buffer(length, maxCapacity());
  copy.writeBytes(this, index, length);
  return copy;
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

@Override
public ByteBuf copy(int index, int length) {
  checkIndex(index, length);
  ByteBuf copy = alloc().buffer(length, maxCapacity());
  copy.writeBytes(this, index, length);
  return copy;
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

@Override
  protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
    if (restoreOldNettyBehaviour) {
      /*
       * For non-credit based code paths with Netty >= 4.0.28.Final:
       * These versions contain an improvement by Netty, which slices a Netty buffer
       * instead of doing a memory copy [1] in the
       * LengthFieldBasedFrameDecoder. In some situations, this
       * interacts badly with our Netty pipeline leading to OutOfMemory
       * errors.
       *
       * [1] https://github.com/netty/netty/issues/3704
       *
       * TODO: remove along with the non-credit based fallback protocol
       */
      ByteBuf frame = ctx.alloc().buffer(length);
      frame.writeBytes(buffer, index, length);
      return frame;
    } else {
      return super.extractFrame(ctx, buffer, index, length);
    }
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime

@Override
  protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
    if (restoreOldNettyBehaviour) {
      /*
       * For non-credit based code paths with Netty >= 4.0.28.Final:
       * These versions contain an improvement by Netty, which slices a Netty buffer
       * instead of doing a memory copy [1] in the
       * LengthFieldBasedFrameDecoder. In some situations, this
       * interacts badly with our Netty pipeline leading to OutOfMemory
       * errors.
       *
       * [1] https://github.com/netty/netty/issues/3704
       *
       * TODO: remove along with the non-credit based fallback protocol
       */
      ByteBuf frame = ctx.alloc().buffer(length);
      frame.writeBytes(buffer, index, length);
      return frame;
    } else {
      return super.extractFrame(ctx, buffer, index, length);
    }
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
  ByteBuf result = null;
  try {
    // TODO Directly serialize to Netty's buffer
    ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(event);
    result = allocateBuffer(allocator, ID, 4 + serializedEvent.remaining() + 16 + 16 + 16);
    result.writeInt(serializedEvent.remaining());
    result.writeBytes(serializedEvent);
    partitionId.getPartitionId().writeTo(result);
    partitionId.getProducerId().writeTo(result);
    receiverId.writeTo(result);
    return result;
  }
  catch (Throwable t) {
    if (result != null) {
      result.release();
    }
    throw new IOException(t);
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime

@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
  ByteBuf result = null;
  try {
    // TODO Directly serialize to Netty's buffer
    ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(event);
    result = allocateBuffer(allocator, ID, 4 + serializedEvent.remaining() + 16 + 16 + 16);
    result.writeInt(serializedEvent.remaining());
    result.writeBytes(serializedEvent);
    partitionId.getPartitionId().writeTo(result);
    partitionId.getProducerId().writeTo(result);
    receiverId.writeTo(result);
    return result;
  }
  catch (Throwable t) {
    if (result != null) {
      result.release();
    }
    throw new IOException(t);
  }
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
  ByteBuf result = null;
  try {
    // TODO Directly serialize to Netty's buffer
    ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(event);
    result = allocateBuffer(allocator, ID, 4 + serializedEvent.remaining() + 16 + 16 + 16);
    result.writeInt(serializedEvent.remaining());
    result.writeBytes(serializedEvent);
    partitionId.getPartitionId().writeTo(result);
    partitionId.getProducerId().writeTo(result);
    receiverId.writeTo(result);
    return result;
  }
  catch (Throwable t) {
    if (result != null) {
      result.release();
    }
    throw new IOException(t);
  }
}

代码示例来源:origin: com.alibaba.blink/flink-queryable-state-client-java

/**
 * Helper for serializing the messages.
 *
 * @param alloc            The {@link ByteBufAllocator} used to allocate the buffer to serialize the message into.
 * @param requestId        The id of the request to which the message refers to.
 * @param messageType    The {@link MessageType type of the message}.
 * @param payload        The serialized version of the message.
 * @return A {@link ByteBuf} containing the serialized message.
 */
private static ByteBuf writePayload(
    final ByteBufAllocator alloc,
    final long requestId,
    final MessageType messageType,
    final byte[] payload) {
  final int frameLength = HEADER_LENGTH + REQUEST_ID_SIZE + payload.length;
  final ByteBuf buf = alloc.ioBuffer(frameLength + Integer.BYTES);
  buf.writeInt(frameLength);
  writeHeader(buf, messageType);
  buf.writeLong(requestId);
  buf.writeBytes(payload);
  return buf;
}

代码示例来源:origin: org.apache.flink/flink-queryable-state-client-java_2.11

/**
 * Helper for serializing the messages.
 *
 * @param alloc            The {@link ByteBufAllocator} used to allocate the buffer to serialize the message into.
 * @param requestId        The id of the request to which the message refers to.
 * @param messageType    The {@link MessageType type of the message}.
 * @param payload        The serialized version of the message.
 * @return A {@link ByteBuf} containing the serialized message.
 */
private static ByteBuf writePayload(
    final ByteBufAllocator alloc,
    final long requestId,
    final MessageType messageType,
    final byte[] payload) {
  final int frameLength = HEADER_LENGTH + REQUEST_ID_SIZE + payload.length;
  final ByteBuf buf = alloc.ioBuffer(frameLength + Integer.BYTES);
  buf.writeInt(frameLength);
  writeHeader(buf, messageType);
  buf.writeLong(requestId);
  buf.writeBytes(payload);
  return buf;
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

@Override
public ByteBuf readBytes(int length) {
  // copied from the one in netty 4.0.50 fixing the wrong allocator being used
  checkReadableBytes(length);
  if (length == 0) {
    return Unpooled.EMPTY_BUFFER;
  }
  ByteBuf buf = alloc().buffer(length, maxCapacity());
  int readerIndex = readerIndex();
  buf.writeBytes(this, readerIndex, length);
  readerIndex(readerIndex + length);
  return buf;
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

@Override
public ByteBuf readBytes(int length) {
  // copied from the one in netty 4.0.50 fixing the wrong allocator being used
  checkReadableBytes(length);
  if (length == 0) {
    return Unpooled.EMPTY_BUFFER;
  }
  ByteBuf buf = alloc().buffer(length, maxCapacity());
  int readerIndex = readerIndex();
  buf.writeBytes(this, readerIndex, length);
  readerIndex(readerIndex + length);
  return buf;
}

代码示例来源:origin: org.apache.flink/flink-runtime

@Override
public ByteBuf readBytes(int length) {
  // copied from the one in netty 4.0.50 fixing the wrong allocator being used
  checkReadableBytes(length);
  if (length == 0) {
    return Unpooled.EMPTY_BUFFER;
  }
  ByteBuf buf = alloc().buffer(length, maxCapacity());
  int readerIndex = readerIndex();
  buf.writeBytes(this, readerIndex, length);
  readerIndex(readerIndex + length);
  return buf;
}

相关文章