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

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

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

Buffer.setBuffer介绍

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

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

代码示例

代码示例来源: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

private void testSetBufferWithOffsetAndLen(Function<byte[], Buffer> bufferFactory) throws Exception {
 int bytesLen = 100;
 byte[] bytes = TestUtils.randomByteArray(bytesLen);
 Buffer src = bufferFactory.apply(bytes);
 int len = bytesLen - 2;
 Buffer b = Buffer.buffer();
 b.setByte(0, (byte) '0');
 b.setBuffer(1, src, 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.setBuffer(b.length(), src, 1, len);
 assertEquals(b.length(), 2 * len + 1);
 assertNullPointerException(() -> b.setBuffer(1, null));
 assertNullPointerException(() -> b.setBuffer(1, null, 0, 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

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

private void testSetBufferWithOffsetAndLen(Function<byte[], Buffer> bufferFactory) throws Exception {
 int bytesLen = 100;
 byte[] bytes = TestUtils.randomByteArray(bytesLen);
 Buffer src = bufferFactory.apply(bytes);
 int len = bytesLen - 2;
 Buffer b = Buffer.buffer();
 b.setByte(0, (byte) '0');
 b.setBuffer(1, src, 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.setBuffer(b.length(), src, 1, len);
 assertEquals(b.length(), 2 * len + 1);
 assertNullPointerException(() -> b.setBuffer(1, null));
 assertNullPointerException(() -> b.setBuffer(1, null, 0, len));
}

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

/**
 * Sets the bytes at position <code>pos</code> in the Buffer to the bytes represented by the <code>Buffer 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 setBuffer(int pos, io.vertx.rxjava.core.buffer.Buffer b) { 
 delegate.setBuffer(pos, b.getDelegate());
 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>Buffer b</code> on the given <code>offset</code> and <code>len</code>.<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 setBuffer(int pos, io.vertx.rxjava.core.buffer.Buffer b, int offset, int len) { 
 delegate.setBuffer(pos, b.getDelegate(), offset, len);
 return this;
}

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

/**
 * Sets the bytes at position <code>pos</code> in the Buffer to the bytes represented by the <code>Buffer 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 setBuffer(int pos, io.vertx.rxjava.core.buffer.Buffer b) { 
 delegate.setBuffer(pos, b.getDelegate());
 return this;
}

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

/**
 * Sets the bytes at position <code>pos</code> in the Buffer to the bytes represented by the <code>Buffer b</code> on the given <code>offset</code> and <code>len</code>.<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 setBuffer(int pos, io.vertx.rxjava.core.buffer.Buffer b, int offset, int len) { 
 delegate.setBuffer(pos, b.getDelegate(), offset, len);
 return this;
}

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

@Override
public void insert(int index, IApimanBuffer buffer) {
  nativeBuffer.setBuffer(index, (Buffer) buffer.getNativeBuffer());
}

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

@Override
public void insert(int index, IApimanBuffer buffer, int offset, int length) {
  nativeBuffer.setBuffer(index, (Buffer) buffer.getNativeBuffer(), offset, 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"));
}

代码示例来源:origin: com.jukusoft/vertx-binary-serializer

buf.setBuffer(_pos, content);
  _pos += content.length();
} else if (clazz == SJsonObject.class) {

代码示例来源:origin: zyclonite/nassh-relay

@Override
  public void update(final Observable queue, final Object arg) {
    if (request instanceof HttpServerRequest) {
      final Buffer buffer = ((TransferQueue) queue).poll();
      queue.deleteObserver(this);
      final HttpServerRequest req = (HttpServerRequest) request;
      assert buffer != null;
      final String encodedBytes = Base64.getUrlEncoder().encodeToString(buffer.getBytes());
      req.response().setStatusCode(200);
      req.response().end(encodedBytes);
    } else if (request instanceof ServerWebSocket) {
      final Buffer buffer = ((TransferQueue) queue).poll();
      final ServerWebSocket ws = (ServerWebSocket) request;
      if (!ws.writeQueueFull()) {
        final Buffer ackbuffer = Buffer.buffer();
        ackbuffer.setInt(0, session.getWrite_count());
        ackbuffer.setBuffer(4, buffer);
        ws.write(ackbuffer);
      } else {
        ws.pause();
      }
    } else {
      queue.deleteObserver(this);
    }
  }
}

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

if(!isEnd || readBufferPosition > 0) {
  final int position = readBufferPosition;
  readBuffer.setBuffer(position, binary);
  readBufferPosition = position + binary.length();

代码示例来源:origin: zyclonite/nassh-relay

final Buffer ackbuffer = Buffer.buffer();
ackbuffer.setInt(0, session.getWrite_count());
ackbuffer.setBuffer(4, buffer);
ws.write(ackbuffer);
queue.remove(buffer);

相关文章