io.netty.buffer.ByteBuf.slice()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(217)

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

ByteBuf.slice介绍

[英]Returns a slice of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method is identical to buf.slice(buf.readerIndex(), buf.readableBytes()). This method does not modify readerIndex or writerIndex of this buffer.

Also be aware that this method will NOT call #retain() and so the reference count will NOT be increased.
[中]返回此缓冲区的可读字节的一个片段。修改返回的缓冲区或此缓冲区的内容会影响彼此的内容,同时它们会维护单独的索引和标记。此方法与buf相同。切片(buf.readerIndex(),buf。readableBytes()。此方法不修改此缓冲区的readerIndex或writerIndex。
还要注意,此方法不会调用#retain(),因此引用计数不会增加。

代码示例

代码示例来源:origin: netty/netty

@Override
  protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
    return buffer.slice(index, length);
  }
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice() {
  return buf.slice();
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice(int index, int length) {
  return buf.slice(index, length);
}

代码示例来源:origin: netty/netty

/**
 * Creates a new big-endian buffer which wraps the sub-region of the
 * specified {@code array}.  A modification on the specified array's
 * content will be visible to the returned buffer.
 */
public static ByteBuf wrappedBuffer(byte[] array, int offset, int length) {
  if (length == 0) {
    return EMPTY_BUFFER;
  }
  if (offset == 0 && length == array.length) {
    return wrappedBuffer(array);
  }
  return wrappedBuffer(array).slice(offset, length);
}

代码示例来源:origin: netty/netty

/**
 * Creates a new buffer which wraps the specified buffer's readable bytes.
 * A modification on the specified buffer's content will be visible to the
 * returned buffer.
 * @param buffer The buffer to wrap. Reference count ownership of this variable is transferred to this method.
 * @return The readable portion of the {@code buffer}, or an empty buffer if there is no readable portion.
 * The caller is responsible for releasing this buffer.
 */
public static ByteBuf wrappedBuffer(ByteBuf buffer) {
  if (buffer.isReadable()) {
    return buffer.slice();
  } else {
    buffer.release();
    return EMPTY_BUFFER;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public NettyDataBuffer slice(int index, int length) {
  ByteBuf slice = this.byteBuf.slice(index, length);
  return new NettyDataBuffer(slice, this.dataBufferFactory);
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice(int index, int length) {
  checkIndex(index, length);
  return buffer.slice(index, length);
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf retainedSlice(int index, int length) {
  checkIndex(index, length);
  return buffer.slice(index, length);
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice() {
  return new UnreleasableByteBuf(buf.slice());
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice(int index, int length) {
  return new UnreleasableByteBuf(buf.slice(index, length));
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice() {
  return buf.slice().order(order);
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice(int index, int length) {
  return unwrap().slice(index, length);
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice(int index, int length) {
  return buf.slice(index, length).order(order);
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice(int index, int length) {
  return Unpooled.unmodifiableBuffer(unwrap().slice(index, length));
}

代码示例来源:origin: netty/netty

ByteBuf slice() {
  return slice != null ? slice : (slice = buf.slice(idx(offset), length()));
}

代码示例来源:origin: eclipse-vertx/vert.x

private static ByteBuf paddedByteBuf(int padding, byte[] bytes) {
 byte[] data = new byte[padding + bytes.length];
 System.arraycopy(bytes, 0, data, padding, bytes.length);
 return Unpooled.copiedBuffer(data).slice(padding, bytes.length);
}

代码示例来源:origin: netty/netty

ByteBuf decode(ByteBuf src, int off, int len, ByteBufAllocator allocator, Base64Dialect dialect) {
  dest = allocator.buffer(decodedBufferSize(len)).order(src.order()); // Upper limit on size of output
  decodabet = decodabet(dialect);
  try {
    src.forEachByte(off, len, this);
    return dest.slice(0, outBuffPosn);
  } catch (Throwable cause) {
    dest.release();
    PlatformDependent.throwException(cause);
    return null;
  }
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf slice(int index, int length) {
  checkIndex0(index, length);
  return unwrap().slice(idx(index), length);
}

代码示例来源:origin: redisson/redisson

@Override
public ByteBuf slice(int index, int length) {
  checkIndex0(index, length);
  return unwrap().slice(idx(index), length);
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testLength2() throws Exception {
 byte[] bytes = TestUtils.randomByteArray(100);
 assertEquals(90, Buffer.buffer(Unpooled.copiedBuffer(bytes).slice(10, 90)).length());
}

相关文章

微信公众号

最新文章

更多

ByteBuf类方法