Class CompressionUtils


  • public class CompressionUtils
    extends java.lang.Object
    This is CompressionUtils that encapsulates common compression calls and operations in one spot.
    Since:
    4.1
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String compress​(java.lang.String srcTxt)
      Use ZipOutputStream to zip text to byte array, then convert byte array to base64 string, so it can be transferred via http request.
      static java.lang.String decodeByteArrayToString​(byte[] bytes)
      Decode the byte[] in base64 to a string.
      static java.lang.String decompress​(java.lang.String zippedBase64Str)
      First decode base64 String to byte array, then use ZipInputStream to revert the byte array to a string.
      static java.lang.String deflate​(byte[] bytes)
      Deflate the given bytes using zlib.
      static java.lang.String deflate​(java.lang.String data)
      Deflate the given string via a Deflater.
      static java.lang.String inflate​(byte[] bytes)
      Inflate the byte[] to a string.
      static org.springframework.core.io.WritableResource toZipFile​(java.util.stream.Stream<?> dataStream, java.util.function.Function<java.lang.Object,​java.io.File> converter, java.lang.String prefix)
      To zip file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CompressionUtils

        public CompressionUtils()
    • Method Detail

      • deflate

        public static java.lang.String deflate​(byte[] bytes)
        Deflate the given bytes using zlib.
        Parameters:
        bytes - the bytes
        Returns:
        the converted string
      • deflate

        public static java.lang.String deflate​(java.lang.String data)
        Deflate the given string via a Deflater.
        Parameters:
        data - the data
        Returns:
        base64 encoded string
      • inflate

        public static java.lang.String inflate​(byte[] bytes)
        Inflate the byte[] to a string.
        Parameters:
        bytes - the data to decode
        Returns:
        the new string
      • decompress

        public static java.lang.String decompress​(java.lang.String zippedBase64Str)
        First decode base64 String to byte array, then use ZipInputStream to revert the byte array to a string.
        Parameters:
        zippedBase64Str - the zipped base 64 str
        Returns:
        the string, or null
      • decodeByteArrayToString

        public static java.lang.String decodeByteArrayToString​(byte[] bytes)
        Decode the byte[] in base64 to a string.
        Parameters:
        bytes - the data to encode
        Returns:
        the new string
      • compress

        public static java.lang.String compress​(java.lang.String srcTxt)
        Use ZipOutputStream to zip text to byte array, then convert byte array to base64 string, so it can be transferred via http request.
        Parameters:
        srcTxt - the src txt
        Returns:
        the string in UTF-8 format and base64'ed, or null.
      • toZipFile

        public static org.springframework.core.io.WritableResource toZipFile​(java.util.stream.Stream<?> dataStream,
                                                                             java.util.function.Function<java.lang.Object,​java.io.File> converter,
                                                                             java.lang.String prefix)
        To zip file.
        Parameters:
        dataStream - the data stream
        converter - the converter
        prefix - the prefix
        Returns:
        the writable resource