当前位置: 首页>>代码示例>>Java>>正文


Java UnpooledByteBufAllocator.buffer方法代码示例

本文整理汇总了Java中io.netty.buffer.UnpooledByteBufAllocator.buffer方法的典型用法代码示例。如果您正苦于以下问题:Java UnpooledByteBufAllocator.buffer方法的具体用法?Java UnpooledByteBufAllocator.buffer怎么用?Java UnpooledByteBufAllocator.buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.UnpooledByteBufAllocator的用法示例。


在下文中一共展示了UnpooledByteBufAllocator.buffer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testParser

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test
public void testParser() throws Exception {
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  CollectdParser parser = new CollectdParser(getContext(), false, null, false, null, CHARSET);
  byte[] bytes = Files.readAllBytes(SINGLE_PACKET.toPath());
  ByteBuf buf = allocator.buffer(bytes.length);
  buf.writeBytes(bytes);
  List<Record> records = parser.parse(buf, null, null);

  Assert.assertEquals(23, records.size()); // 23 Value parts

  Record record0 = records.get(0);
  UDPTestUtil.verifyCollectdRecord(UDPTestUtil.expectedRecord0, record0);

  Record record2 = records.get(2);
  UDPTestUtil.verifyCollectdRecord(UDPTestUtil.expectedRecord2, record2);

}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:TestCollectdParser.java

示例2: testParserExcludeInterval

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test
public void testParserExcludeInterval() throws Exception {
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  CollectdParser parser = new CollectdParser(getContext(), false, null, true, null, CHARSET);
  byte[] bytes = Files.readAllBytes(SINGLE_PACKET.toPath());
  ByteBuf buf = allocator.buffer(bytes.length);
  buf.writeBytes(bytes);
  List<Record> records = parser.parse(buf, null, null);

  Assert.assertEquals(23, records.size()); // 23 Value parts

  Record record0 = records.get(0);
  UDPTestUtil.verifyCollectdRecord(UDPTestUtil.expectedRecordNoInterval0, record0);

  Record record2 = records.get(2);
  UDPTestUtil.verifyCollectdRecord(UDPTestUtil.expectedRecordNoInterval2, record2);

}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:TestCollectdParser.java

示例3: testEncryptedRecord

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test
public void testEncryptedRecord() throws Exception {
  // If unlimited strength encryption is not available, we cant run this test.
  Assume.assumeFalse(Cipher.getMaxAllowedKeyLength("AES") < 256);

  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  CollectdParser parser = new CollectdParser(getContext(), false, null, false, AUTH_FILE_PATH, CHARSET);
  byte[] bytes = Files.readAllBytes(SINGLE_ENCRYPTED_PACKET.toPath());
  ByteBuf buf = allocator.buffer(bytes.length);
  buf.writeBytes(bytes);
  List<Record> records = parser.parse(buf, null, null);

  Assert.assertEquals(24, records.size()); // 24 value parts
  Record record14 = records.get(14);
  UDPTestUtil.verifyCollectdRecord(UDPTestUtil.encryptedRecord14, record14);
  LOG.info("Num records: {}", records.size());
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:18,代码来源:TestCollectdParser.java

示例4: testParseFailure

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test
public void testParseFailure() throws Exception {
  SyslogParser parser = new SyslogParser(getContext(), StandardCharsets.UTF_8);
  String msg = "<123>                    ";
  byte[] bytes = msg.getBytes(StandardCharsets.UTF_8);
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  ByteBuf buffer = allocator.buffer(bytes.length);
  buffer.writeBytes(bytes);
  try {
    parser.parse(
        buffer,
        InetSocketAddress.createUnresolved("localhost", 5000),
        InetSocketAddress.createUnresolved("localhost", 50000)
    );
    Assert.fail("Expected OnRecordErrorException");
  } catch (OnRecordErrorException ex) {
    Record record = ex.getRecord();
    Assert.assertEquals(msg, record.get().getValueAsString());
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:21,代码来源:TestSyslogParser.java

示例5: testInvalidVersion

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test(expected = OnRecordErrorException.class)
public void testInvalidVersion() throws Exception {
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  NetflowParser netflowParser = makeNetflowParser();
  ByteBuf buf = allocator.buffer(4);
  buf.writeShort(0);
  buf.writeShort(0);
  netflowParser.parse(buf, null, null);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:10,代码来源:TestNetflowParser.java

示例6: testInvalidCountInvalidLength

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test(expected = OnRecordErrorException.class)
public void testInvalidCountInvalidLength() throws Exception {
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  NetflowParser netflowParser = makeNetflowParser();
  ByteBuf buf = allocator.buffer(4);
  buf.writeShort(5);
  buf.writeShort(1);
  netflowParser.parse(buf, null, null);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:10,代码来源:TestNetflowParser.java

示例7: testInvalidCountZero

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test(expected = OnRecordErrorException.class)
public void testInvalidCountZero() throws Exception {
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  NetflowParser netflowParser = makeNetflowParser();
  ByteBuf buf = allocator.buffer(4);
  buf.writeShort(5);
  buf.writeShort(0);
  netflowParser.parse(buf, null, null);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:10,代码来源:TestNetflowParser.java

示例8: testInvalidPacketTooShort1

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test(expected = OnRecordErrorException.class)
public void testInvalidPacketTooShort1() throws Exception {
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  NetflowParser netflowParser = makeNetflowParser();
  ByteBuf buf = allocator.buffer(0);
  netflowParser.parse(buf, null, null);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:8,代码来源:TestNetflowParser.java

示例9: testInvalidPacketTooShort2

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test(expected = OnRecordErrorException.class)
public void testInvalidPacketTooShort2() throws Exception {
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  NetflowParser netflowParser = makeNetflowParser();
  ByteBuf buf = allocator.buffer(2);
  buf.writeShort(5);
  netflowParser.parse(buf, null, null);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:9,代码来源:TestNetflowParser.java

示例10: testV5

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test
public void testV5() throws Exception {
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  NetflowParser netflowParser = makeNetflowParser();
  byte[] bytes = Resources.toByteArray(Resources.getResource(TEN_PACKETS));
  ByteBuf buf = allocator.buffer(bytes.length);
  buf.writeBytes(bytes);
  List<Record> records = netflowParser.parse(buf, null, null);
  NetflowTestUtil.assertRecordsForTenPackets(records);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:11,代码来源:TestNetflowParser.java

示例11: testSignedRecord

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test
public void testSignedRecord() throws Exception {
  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  CollectdParser parser = new CollectdParser(getContext(), false, null, false, AUTH_FILE_PATH, CHARSET);
  byte[] bytes = Files.readAllBytes(SINGLE_SIGNED_PACKET.toPath());
  ByteBuf buf = allocator.buffer(bytes.length);
  buf.writeBytes(bytes);
  List<Record> records = parser.parse(buf, null, null);

  Assert.assertEquals(22, records.size()); // 22 value parts
  Record record15 = records.get(15);
  UDPTestUtil.verifyCollectdRecord(UDPTestUtil.signedRecord15, record15);
  LOG.info("Num records: {}", records.size());
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:15,代码来源:TestCollectdParser.java

示例12: testMessageParsing

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test
public void testMessageParsing() throws Exception {
  SyslogParser parser = new SyslogParser(getContext(), StandardCharsets.UTF_8);
  List<String> messages = getTestMessageStrings();

  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  // test with default keepFields = false
  for (String msg : messages) {
    byte[] bytes = msg.getBytes(StandardCharsets.UTF_8);
    ByteBuf buffer = allocator.buffer(bytes.length);
    buffer.writeBytes(bytes);
    List<Record> records = parser.parse(
        buffer,
        InetSocketAddress.createUnresolved("localhost", 5000),
        InetSocketAddress.createUnresolved("localhost", 50000)
    );
    Assert.assertEquals(1, records.size());
    Assert.assertEquals("Failure to parse known-good syslog message",
      msg, records.get(0).get("/raw").getValueAsString());
    Assert.assertEquals("Failure to parse known-good syslog message",
      "localhost:5000", records.get(0).get("/receiverAddr").getValueAsString());
    Assert.assertEquals("Failure to parse known-good syslog message",
      "localhost:50000", records.get(0).get("/senderAddr").getValueAsString());
    Assert.assertNotNull("Failure to parse known-good syslog message",
      records.get(0).get("/host").getValueAsString());
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:28,代码来源:TestSyslogParser.java

示例13: testMessageParsingIPv6

import io.netty.buffer.UnpooledByteBufAllocator; //导入方法依赖的package包/类
@Test
public void testMessageParsingIPv6() throws Exception {
  SyslogParser parser = new SyslogParser(getContext(), StandardCharsets.UTF_8);
  List<String> messages = getTestMessageStrings();

  UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
  // test with default keepFields = false
  for (String msg : messages) {
    byte[] bytes = msg.getBytes(StandardCharsets.UTF_8);
    ByteBuf buffer = allocator.buffer(bytes.length);
    buffer.writeBytes(bytes);
    List<Record> records = parser.parse(
        buffer,
        InetSocketAddress.createUnresolved("::1", 5000),
        InetSocketAddress.createUnresolved("2001:db8::ff00:42:8329", 50000)
    );
    Assert.assertEquals(1, records.size());
    Assert.assertEquals("Failure to parse known-good syslog message",
        msg, records.get(0).get("/raw").getValueAsString());
    Assert.assertEquals("Failure to parse known-good syslog message",
        "[::1]:5000", records.get(0).get("/receiverAddr").getValueAsString());
    Assert.assertEquals("Failure to parse known-good syslog message",
        "[2001:db8::ff00:42:8329]:50000", records.get(0).get("/senderAddr").getValueAsString());
    Assert.assertNotNull("Failure to parse known-good syslog message",
        records.get(0).get("/host").getValueAsString());
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:28,代码来源:TestSyslogParser.java


注:本文中的io.netty.buffer.UnpooledByteBufAllocator.buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。