Ejemplo n.º 1
0
  @Test
  public void testDeflateAndInflate_OutputIsMultiple() throws Exception {
    byte[] data = new byte[512];
    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);

    assertProcessedData(data);
    assertThat(((ArrayCodecBuffer) deflaterInput).referenceCount(), is(0));
    assertThat(((ArrayCodecBuffer) inflaterInput).referenceCount(), is(0));
  }
Ejemplo n.º 2
0
  @Test
  public void testDeflateAndInflate_DeflaterBufferIsSmall() throws Exception {
    byte[] data = new byte[512];
    Arrays.fill(data, (byte) '0');
    CodecBuffer deflaterInput = Buffers.wrap(data, 0, data.length);
    DeflaterEncoder encoder = new DeflaterEncoder(Deflater.BEST_SPEED, 8, null, false);
    encoder.stored(context_, deflaterInput, null);
    CodecBuffer inflaterInput = context_.pollEvent();
    if (context_.pollEvent() != null) {
      Assert.fail();
    }
    InflaterDecoder decoder = new InflaterDecoder();
    decoder.loaded(context_, inflaterInput, null);

    assertProcessedData(data);
    assertThat(((ArrayCodecBuffer) deflaterInput).referenceCount(), is(0));
    assertThat(((ArrayCodecBuffer) inflaterInput).referenceCount(), is(0));
  }
Ejemplo n.º 3
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));
  }
Ejemplo n.º 4
0
 private void assertProcessedData(byte[] data) {
   byte[] decompressed = new byte[data.length];
   int n = 0;
   for (; ; ) {
     CodecBuffer b = context_.pollEvent();
     if (b == null) {
       break;
     }
     n += b.readBytes(decompressed, n, decompressed.length - n);
   }
   assertThat(decompressed, is(data));
   assertThat(n, is(data.length));
 }