Ejemplo n.º 1
0
  @Test
  public void testDeflateAndInflate_NeedsInput() throws Exception {
    byte[] data = new byte[512];
    Arrays.fill(data, (byte) '0');
    CodecBuffer deflaterInput = Buffers.wrap(data, 0, data.length);

    DeflaterEncoder encoder = new DeflaterEncoder();
    encoder.stored(context_, deflaterInput, null);
    CodecBuffer inflaterInput = context_.pollEvent();
    if (context_.pollEvent() != null) {
      Assert.fail();
    }
    InflaterDecoder decoder = new InflaterDecoder();
    decoder.loaded(context_, inflaterInput.slice(8), null);
    decoder.loaded(context_, inflaterInput, null);

    assertProcessedData(data);
    assertThat(((ArrayCodecBuffer) deflaterInput).referenceCount(), is(0));
    assertThat(((ArrayCodecBuffer) inflaterInput).referenceCount(), is(0));
  }
Ejemplo n.º 2
0
  @Test
  public void testDeflateAndInflate_Simple() throws Exception {
    byte[] data =
        "0123456789012345678901234567890123456789012345678901234567890123456789".getBytes("UTF-8");
    CodecBuffer deflaterInput = Buffers.wrap(data, 0, data.length);

    DeflaterEncoder encoder = new DeflaterEncoder();
    encoder.stored(context_, deflaterInput, null);
    CodecBuffer inflaterInput = context_.pollEvent();
    if (context_.pollEvent() != null) {
      Assert.fail();
    }
    InflaterDecoder decoder = new InflaterDecoder();
    decoder.loaded(context_, inflaterInput, null);

    CodecBuffer inflated = context_.pollEvent();
    assertThat(inflated.remaining(), is(data.length));
    assertThat(decoder.output(), is(nullValue()));
    assertThat(((ArrayCodecBuffer) deflaterInput).referenceCount(), is(0));
    assertThat(((ArrayCodecBuffer) inflaterInput).referenceCount(), is(0));
  }