@ SneakyThrows ( IOException . class ) public static String compressToBase64 ( final String string ) { Preconditions . checkNotNull ( string , "string" ) ; @ Cleanup final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; @ Cleanup final OutputStream base64OutputStream = Base64 . getEncoder ( ) . wrap ( byteArrayOutputStream ) ; @ Cleanup final GZIPOutputStream gzipOutputStream = new GZIPOutputStream ( base64OutputStream ) ; gzipOutputStream . write ( string . getBytes ( UTF_8 ) ) ; gzipOutputStream . close ( ) ; return byteArrayOutputStream . toString ( UTF_8 . name ( ) ) ; }
Convert the given string to its compressed base64 representation .