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

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

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

Buffer.buffer介绍

[英]Create a new, empty buffer.
[中]创建一个新的空缓冲区。

代码示例

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

@Override
 public void handle(Object event) {
  if (event instanceof ByteBuf) {
   ByteBuf byteBuf = (ByteBuf) event;
   byteBuf = VertxHandler.safeBuffer(byteBuf, allocator);
   Buffer data = Buffer.buffer(byteBuf);
   reportBytesRead(data.length());
   dataHandler.handle(data);
  }
 }
}

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

@Test
/*
 * test issue-209
 */
public void testSpreadDelimiter() {
 doTestDelimited(Buffer.buffer("start-a-b-c-dddabc"), Buffer.buffer("abc"),
  new Integer[] { 18 }, Buffer.buffer("start-a-b-c-ddd"));
 doTestDelimited(Buffer.buffer("start-abc-dddabc"), Buffer.buffer("abc"),
  new Integer[] { 18 }, Buffer.buffer("start-"), Buffer.buffer("-ddd"));
 doTestDelimited(Buffer.buffer("start-ab-c-dddabc"), Buffer.buffer("abc"),
  new Integer[] { 18 }, Buffer.buffer("start-ab-c-ddd"));
}

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

@Test
public void testLength() throws Exception {
 byte[] bytes = TestUtils.randomByteArray(100);
 Buffer buffer = Buffer.buffer(bytes);
 assertEquals(100, Buffer.buffer(buffer.getByteBuf()).length());
}

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

@Test
public void testDecodeValue() {
 assertDecodeValue(Buffer.buffer("42"), 42, INTEGER_TYPE_REF);
 assertDecodeValue(Buffer.buffer("42"), 42L, LONG_TYPE_REF);
 assertDecodeValue(Buffer.buffer("\"foobar\""), "foobar", STRING_TYPE_REF);
 assertDecodeValue(Buffer.buffer("3.4"), 3.4f, FLOAT_TYPE_REF);
 assertDecodeValue(Buffer.buffer("3.4"), 3.4d, DOUBLE_TYPE_REF);
 assertDecodeValue(Buffer.buffer("{\"foo\":4}"), Collections.singletonMap("foo", 4), MAP_TYPE_REF);
 assertDecodeValue(Buffer.buffer("[0,1,2]"), Arrays.asList(0, 1, 2), LIST_TYPE_REF);
 assertDecodeValue(Buffer.buffer("true"), true, BOOLEAN_TYPE_REF);
 assertDecodeValue(Buffer.buffer("false"), false, BOOLEAN_TYPE_REF);
}

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

@Test
public void testAppendByte2() throws Exception {
 int bytesLen = 100;
 Buffer b = Buffer.buffer(TestUtils.randomByteArray(bytesLen));
 b.setByte(b.length(), (byte) 9);
}

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

private Buffer loadJsonAsBuffer(URL url) {
 try {
  Buffer encoded = new JsonObject(Json.mapper.readValue(url, Map.class)).toBuffer();
  return Buffer.buffer().appendInt(encoded.length()).appendBuffer(encoded);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

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

@Test
public void testConstructorArguments() throws Exception {
 assertIllegalArgumentException(() -> Buffer.buffer(-1));
 assertNullPointerException(() -> Buffer.buffer((byte[]) null));
 assertNullPointerException(() -> Buffer.buffer((String) null));
 assertNullPointerException(() -> Buffer.buffer((ByteBuf) null));
 assertNullPointerException(() -> Buffer.buffer(null, "UTF-8"));
 assertNullPointerException(() -> Buffer.buffer("", null));
}

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

@Test
public void testCreateBuffers() throws Exception {
 Buffer buff = Buffer.buffer(1000);
 assertEquals(0, buff.length());
 String str = TestUtils.randomUnicodeString(100);
 buff = Buffer.buffer(str);
 assertEquals(buff.length(), str.getBytes("UTF-8").length);
 assertEquals(str, buff.toString());
 // TODO create with string with encoding
 byte[] bytes = TestUtils.randomByteArray(100);
 buff = Buffer.buffer(bytes);
 assertEquals(buff.length(), bytes.length);
 assertEquals(Buffer.buffer(bytes), Buffer.buffer(buff.getBytes()));
}

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

void testEchoStringWithEncoding(String encoding) {
 String sent = TestUtils.randomUnicodeString(100);
 Buffer buffSent = Buffer.buffer(sent, encoding);
 testEcho(sock -> sock.write(sent, encoding), buff -> assertEquals(buffSent, buff), buffSent.length());
}

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

@Test
public void testSetInt() throws Exception {
 testSetInt(Buffer.buffer(numSets * 4));
}

代码示例来源: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());
}

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

private void direct(JsonObject jsonObject) throws Exception {
  Buffer buffer = Buffer.buffer();
  Buffer encoded = jsonObject.toBuffer();
  buffer.appendInt(encoded.length());
  buffer.appendBuffer(encoded);
  consume(buffer);
 }
}

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

@Test
public void testSetUnsignedIntExpandBuffer() throws Exception {
 testSetUnsignedInt(Buffer.buffer());
}

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

@Test
public void testAppendUnsignedByte() {
 Buffer b = Buffer.buffer(TestUtils.randomByteArray(100));
 b.appendUnsignedByte((short) (Byte.MAX_VALUE + Byte.MAX_VALUE / 2));
 assertEquals(101, b.length());
}

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

private void testSetBytesString(Buffer buff) throws Exception {
 String str = TestUtils.randomUnicodeString(100);
 buff.setString(50, str);
 byte[] b1 = buff.getBytes(50, buff.length());
 String str2 = new String(b1, "UTF-8");
 assertEquals(str, str2);
 assertNullPointerException(() -> Buffer.buffer(150).setString(0, null));
 assertNullPointerException(() -> Buffer.buffer(150).setString(0, null, "UTF-8"));
 //TODO setString with encoding
}

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

@Test
public void testSetByteExpandBuffer() throws Exception {
 testSetByte(Buffer.buffer());
}

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

@Test
public void testEchoString() {
 String sent = TestUtils.randomUnicodeString(100);
 Buffer buffSent = Buffer.buffer(sent);
 testEcho(sock -> sock.write(sent), buff -> assertEquals(buffSent, buff), buffSent.length());
}

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

public void testAppendBuff(Function<byte[], Buffer> bufferFactory) throws Exception {
 int bytesLen = 100;
 byte[] bytes = TestUtils.randomByteArray(bytesLen);
 Buffer toAppend = bufferFactory.apply(bytes);
 Buffer b = Buffer.buffer();
 b.appendBuffer(toAppend);
 assertEquals(b.length(), bytes.length);
 assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes()));
 b.appendBuffer(toAppend);
 assertEquals(b.length(), 2 * bytes.length);
 assertNullPointerException(() -> b.appendBuffer(null));
}

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

@Test
public void testSetFloat() throws Exception {
 testSetFloat(Buffer.buffer(numSets * 4));
}

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

@Test
public void testAppendMedium() {
 Buffer b = Buffer.buffer(TestUtils.randomByteArray(100));
 b.appendMedium(MEDIUM_MAX_VALUE);
 assertEquals(103, b.length());
 b.appendMediumLE(MEDIUM_MAX_VALUE);
 assertEquals(106, b.length());
}

相关文章