private static String getBase64EncodedString ( String str ) { ByteBuf byteBuf = null ; ByteBuf encodedByteBuf = null ; try { byteBuf = Unpooled . wrappedBuffer ( str . getBytes ( StandardCharsets . UTF_8 ) ) ; encodedByteBuf = Base64 . encode ( byteBuf ) ; return encodedByteBuf . toString ( StandardCharsets . UTF_8 ) ; } finally { // The release is called to suppress the memory leak error messages raised by netty. if ( byteBuf != null ) { byteBuf . release ( ) ; if ( encodedByteBuf != null ) { encodedByteBuf . release ( ) ; } } } }
Return a Base64 - encoded string .