@SuppressJava6Requirement(reason = "Guarded with java version check")
    static String base64(byte[] data) {
        if (PlatformDependent.javaVersion() >= 8) {
            return java.util.Base64.getEncoder().encodeToString(data);
        }
        String encodedString;
        ByteBuf encodedData = Unpooled.wrappedBuffer(data);
        try {
            ByteBuf encoded = Base64.encode(encodedData);
            try {
                encodedString = encoded.toString(CharsetUtil.UTF_8);
            } finally {
                encoded.release();
            }
        } finally {
            encodedData.release();
        }
        return encodedString;
    }
@Test
    public void testBase64() {
        String base64 = WebSocketUtil.base64(EmptyArrays.EMPTY_BYTES);
        assertNotNull(base64);
        assertTrue(base64.isEmpty());

        base64 = WebSocketUtil.base64("foo".getBytes(CharsetUtil.UTF_8));
        assertEquals(base64, "Zm9v");

        base64 = WebSocketUtil.base64("bar".getBytes(CharsetUtil.UTF_8));
        ByteBuf src = Unpooled.wrappedBuffer(base64.getBytes(CharsetUtil.UTF_8));
        try {
            ByteBuf dst = Base64.decode(src);
            try {
                assertEquals(new String(ByteBufUtil.getBytes(dst), CharsetUtil.UTF_8), "bar");
            } finally {
                dst.release();
            }
        } finally {
            src.release();
        }
    }