public static ByteBuffer ensureCapacity(ByteBuffer existingBuffer, int newLength) {
        if (newLength > existingBuffer.capacity()) {
            ByteBuffer newBuffer = ByteBuffer.allocate(newLength);
            existingBuffer.flip();
            newBuffer.put(existingBuffer);
            return newBuffer;
        }
        return existingBuffer;
    }
@Test
    public void ensureCapacityTest() {
        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        ByteBuffer newByteBuffer = Utils.ensureCapacity(byteBuffer, 5);
        assertEquals(10, newByteBuffer.capacity());

        ByteBuffer byteBuffer2 = ByteBuffer.allocate(10);
        ByteBuffer newByteBuffer2 = Utils.ensureCapacity(byteBuffer2, 15);
        assertEquals(15, newByteBuffer2.capacity());

        ByteBuffer byteBuffer3 = ByteBuffer.allocate(10);
        for (int i = 1; i <= 10; i++) {
            byteBuffer3.put((byte) i);
        }
        ByteBuffer newByteBuffer3 = Utils.ensureCapacity(byteBuffer3, 15);
        newByteBuffer3.flip();
        assertEquals(15, newByteBuffer3.capacity());
        assertEquals(1, newByteBuffer3.get());
        assertEquals(2, newByteBuffer3.get());
        assertEquals(3, newByteBuffer3.get());
    }