io.vertx.core.buffer.Buffer.setBytes()方法的使用及代码示例

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

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

Buffer.setBytes介绍

[英]Sets the bytes at position pos in the Buffer to the bytes represented by the ByteBuffer b.

The buffer will expand as necessary to accommodate any value written.
[中]将缓冲区中位置pos处的字节设置为ByteBuffer b表示的字节。
缓冲区将根据需要扩展以容纳任何写入的值。

代码示例

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

@Test
public void testSetBytesBuffer2() throws Exception {
 testSetBytesBuffer(Buffer.buffer(150), PADDED_BUFFER_FACTORY);
 assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (ByteBuffer) null));
}

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

@Test
public void testSetBytesBuffer() throws Exception {
 testSetBytesBuffer(Buffer.buffer(150), Buffer::buffer);
 assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (ByteBuffer) null));
}

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

private void testSetBytesBuffer(Buffer buff, Function<byte[], Buffer> bufferFactory) throws Exception {
 Buffer b = bufferFactory.apply(TestUtils.randomByteArray(100));
 buff.setBuffer(50, b);
 byte[] b2 = buff.getBytes(50, 150);
 assertEquals(b, Buffer.buffer(b2));
 byte[] b3 = TestUtils.randomByteArray(100);
 buff.setBytes(50, b3);
 byte[] b4 = buff.getBytes(50, 150);
 assertEquals(Buffer.buffer(b3), Buffer.buffer(b4));
}

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

@Test
public void testSetBytesWithOffsetAndLen() throws Exception {
 int bytesLen = 100;
 byte[] bytes = TestUtils.randomByteArray(bytesLen);
 int len = bytesLen - 2;
 Buffer b = Buffer.buffer();
 b.setByte(0, (byte) '0');
 b.setBytes(1, bytes, 1, len);
 assertEquals(b.length(), len + 1);
 byte[] copy = new byte[len];
 System.arraycopy(bytes, 1, copy, 0, len);
 assertTrue(TestUtils.byteArraysEqual(copy, b.getBytes(1, b.length())));
 b.setBytes(b.length(), bytes, 1, len);
 assertEquals(b.length(), 2 * len + 1);
 assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (byte[]) null));
 assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, null, 1, len));
}

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

@Test
public void testSetOutOfBounds() throws Exception {
 Buffer b = Buffer.buffer(numSets);
 assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0));
 assertIndexOutOfBoundsException(() -> b.setInt(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setLong(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0));
 assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b));
 assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0));
 assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1)));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1));
 assertIndexOutOfBoundsException(() -> b.setString(-1, ""));
 assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8"));
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testSetBytesBuffer2() throws Exception {
 testSetBytesBuffer(Buffer.buffer(150), PADDED_BUFFER_FACTORY);
 assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (ByteBuffer) null));
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testSetBytesBuffer() throws Exception {
 testSetBytesBuffer(Buffer.buffer(150), Buffer::buffer);
 assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (ByteBuffer) null));
}

代码示例来源:origin: io.vertx/vertx-core

private void testSetBytesBuffer(Buffer buff, Function<byte[], Buffer> bufferFactory) throws Exception {
 Buffer b = bufferFactory.apply(TestUtils.randomByteArray(100));
 buff.setBuffer(50, b);
 byte[] b2 = buff.getBytes(50, 150);
 assertEquals(b, Buffer.buffer(b2));
 byte[] b3 = TestUtils.randomByteArray(100);
 buff.setBytes(50, b3);
 byte[] b4 = buff.getBytes(50, 150);
 assertEquals(Buffer.buffer(b3), Buffer.buffer(b4));
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testSetBytesWithOffsetAndLen() throws Exception {
 int bytesLen = 100;
 byte[] bytes = TestUtils.randomByteArray(bytesLen);
 int len = bytesLen - 2;
 Buffer b = Buffer.buffer();
 b.setByte(0, (byte) '0');
 b.setBytes(1, bytes, 1, len);
 assertEquals(b.length(), len + 1);
 byte[] copy = new byte[len];
 System.arraycopy(bytes, 1, copy, 0, len);
 assertTrue(TestUtils.byteArraysEqual(copy, b.getBytes(1, b.length())));
 b.setBytes(b.length(), bytes, 1, len);
 assertEquals(b.length(), 2 * len + 1);
 assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (byte[]) null));
 assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, null, 1, len));
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Sets the bytes at position <code>pos</code> in the Buffer to the bytes represented by the <code>byte[] b</code>.<p>
 * The buffer will expand as necessary to accommodate any value written.
 * @param pos 
 * @param b 
 * @return 
 */
public io.vertx.rxjava.core.buffer.Buffer setBytes(int pos, byte[] b) { 
 delegate.setBytes(pos, b);
 return this;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Sets the bytes at position <code>pos</code> in the Buffer to the bytes represented by the <code>ByteBuffer b</code>.<p>
 * The buffer will expand as necessary to accommodate any value written.
 * @param pos 
 * @param b 
 * @return 
 */
public io.vertx.rxjava.core.buffer.Buffer setBytes(int pos, ByteBuffer b) { 
 delegate.setBytes(pos, b);
 return this;
}

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

@Override
public void insert(int index, byte[] b, int offset, int length) {
  nativeBuffer.setBytes(index, b, offset, length);
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Sets the bytes at position <code>pos</code> in the Buffer to the bytes represented by the <code>byte[] b</code>.<p>
 * The buffer will expand as necessary to accommodate any value written.
 * @param pos 
 * @param b 
 * @return 
 */
public io.vertx.rxjava.core.buffer.Buffer setBytes(int pos, byte[] b) { 
 delegate.setBytes(pos, b);
 return this;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Sets the given number of bytes at position <code>pos</code> in the Buffer to the bytes represented by the <code>byte[] b</code>.<p></p>
 * The buffer will expand as necessary to accommodate any value written.
 * @param pos 
 * @param b 
 * @param offset 
 * @param len 
 * @return 
 */
public io.vertx.rxjava.core.buffer.Buffer setBytes(int pos, byte[] b, int offset, int len) { 
 delegate.setBytes(pos, b, offset, len);
 return this;
}

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

@Override
public void insert(int index, byte[] b) {
  nativeBuffer.setBytes(index, b);
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Sets the bytes at position <code>pos</code> in the Buffer to the bytes represented by the <code>ByteBuffer b</code>.<p>
 * The buffer will expand as necessary to accommodate any value written.
 * @param pos 
 * @param b 
 * @return 
 */
public io.vertx.rxjava.core.buffer.Buffer setBytes(int pos, ByteBuffer b) { 
 delegate.setBytes(pos, b);
 return this;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Sets the given number of bytes at position <code>pos</code> in the Buffer to the bytes represented by the <code>byte[] b</code>.<p></p>
 * The buffer will expand as necessary to accommodate any value written.
 * @param pos 
 * @param b 
 * @param offset 
 * @param len 
 * @return 
 */
public io.vertx.rxjava.core.buffer.Buffer setBytes(int pos, byte[] b, int offset, int len) { 
 delegate.setBytes(pos, b, offset, len);
 return this;
}

代码示例来源:origin: mewna/catnip

@Override
public void write(@Nonnull final byte[] b, final int off, final int len) {
  buffer.setBytes(startOffset + position, b, off, len);
  position += len;
}

代码示例来源:origin: mewna/catnip

@Override
public void write(@Nonnull final byte[] b) {
  buffer.setBytes(startOffset + position, b);
  position += b.length;
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testSetOutOfBounds() throws Exception {
 Buffer b = Buffer.buffer(numSets);
 assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0));
 assertIndexOutOfBoundsException(() -> b.setInt(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setLong(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0));
 assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b));
 assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0));
 assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1)));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1));
 assertIndexOutOfBoundsException(() -> b.setString(-1, ""));
 assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8"));
}

相关文章