예제 #1
0
  @Test
  public void testGenerateParseOneByteAtATime() {
    DataGenerator generator = new DataGenerator(new HeaderGenerator());

    final List<DataFrame> frames = new ArrayList<>();
    Parser parser =
        new Parser(
            new Parser.Listener.Adapter() {
              @Override
              public void onData(DataFrame frame) {
                frames.add(frame);
              }
            },
            4096,
            8192);

    ByteBuffer data = ByteBuffer.wrap(largeContent);
    List<ByteBuffer> list = generator.generateData(13, data.slice(), true, data.remaining());

    for (ByteBuffer buffer : list) {
      while (buffer.hasRemaining()) {
        parser.parse(ByteBuffer.wrap(new byte[] {buffer.get()}));
      }
    }

    Assert.assertEquals(largeContent.length, frames.size());
  }
예제 #2
0
  private List<DataFrame> testGenerateParse(ByteBuffer data) {
    DataGenerator generator = new DataGenerator(new HeaderGenerator());

    final List<DataFrame> frames = new ArrayList<>();
    Parser parser =
        new Parser(
            new Parser.Listener.Adapter() {
              @Override
              public void onData(DataFrame frame) {
                frames.add(frame);
              }
            },
            4096,
            8192);

    // Iterate a few times to be sure generator and parser are properly
    // reset.
    for (int i = 0; i < 2; ++i) {
      List<ByteBuffer> list = generator.generateData(13, data.slice(), true, data.remaining());

      frames.clear();
      for (ByteBuffer buffer : list) {
        parser.parse(buffer);
      }
    }

    return frames;
  }