Пример #1
0
 @Test
 public void shouldHaveSameByteOrder() {
   ByteBuf buf = Unpooled.buffer(1);
   assertSame(Unpooled.BIG_ENDIAN, Unpooled.unmodifiableBuffer(buf).order());
   buf = buf.order(LITTLE_ENDIAN);
   assertSame(Unpooled.LITTLE_ENDIAN, Unpooled.unmodifiableBuffer(buf).order());
 }
Пример #2
0
 @Test
 public void shouldReturnReadOnlyDerivedBuffer() {
   ByteBuf buf = Unpooled.unmodifiableBuffer(Unpooled.buffer(1));
   assertTrue(buf.duplicate() instanceof ReadOnlyByteBuf);
   assertTrue(buf.slice() instanceof ReadOnlyByteBuf);
   assertTrue(buf.slice(0, 1) instanceof ReadOnlyByteBuf);
   assertTrue(buf.duplicate() instanceof ReadOnlyByteBuf);
 }
  @Override
  protected ByteBuf newBuffer(int length) {
    buffers = new ArrayList<ByteBuf>();
    for (int i = 0; i < length + 45; i += 45) {
      buffers.add(EMPTY_BUFFER);
      buffers.add(wrappedBuffer(new byte[1]));
      buffers.add(EMPTY_BUFFER);
      buffers.add(wrappedBuffer(new byte[2]));
      buffers.add(EMPTY_BUFFER);
      buffers.add(wrappedBuffer(new byte[3]));
      buffers.add(EMPTY_BUFFER);
      buffers.add(wrappedBuffer(new byte[4]));
      buffers.add(EMPTY_BUFFER);
      buffers.add(wrappedBuffer(new byte[5]));
      buffers.add(EMPTY_BUFFER);
      buffers.add(wrappedBuffer(new byte[6]));
      buffers.add(EMPTY_BUFFER);
      buffers.add(wrappedBuffer(new byte[7]));
      buffers.add(EMPTY_BUFFER);
      buffers.add(wrappedBuffer(new byte[8]));
      buffers.add(EMPTY_BUFFER);
      buffers.add(wrappedBuffer(new byte[9]));
      buffers.add(EMPTY_BUFFER);
    }

    buffer =
        Unpooled.wrappedBuffer(Integer.MAX_VALUE, buffers.toArray(new ByteBuf[buffers.size()]))
            .order(order);

    // Truncate to the requested capacity.
    buffer.capacity(length);

    assertEquals(length, buffer.capacity());
    assertEquals(length, buffer.readableBytes());
    assertFalse(buffer.isWritable());
    buffer.writerIndex(0);
    return buffer;
  }
Пример #4
0
 @Test
 public void shouldReturnWritableCopy() {
   ByteBuf buf = Unpooled.unmodifiableBuffer(Unpooled.buffer(1));
   assertFalse(buf.copy() instanceof ReadOnlyByteBuf);
 }
Пример #5
0
 @Test
 public void testUnwrap() {
   ByteBuf buf = Unpooled.buffer(1);
   assertSame(buf, ((WrappedByteBuf) Unpooled.unmodifiableBuffer(buf)).unwrap());
 }
Пример #6
0
 @Test
 public void testUnmodifiableBuffer() {
   assertTrue(Unpooled.unmodifiableBuffer(Unpooled.buffer(1)) instanceof ReadOnlyByteBuf);
 }