Class GZIPHelper


  • public class GZIPHelper
    extends java.lang.Object
    GZIPHelper is a utility class to compress/decompress data using GZIP alorithm (aka LZ77 algorithm). It also provide functions to encode the result of compression into a String or decode it into a byte array using Base64 algorithm.
    Since:
    MicroStrategy Web 8.1.1
    • Constructor Summary

      Constructors 
      Constructor Description
      GZIPHelper()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String base64AndDecompress​(java.lang.String fromString, int estimateRatio)
      De-transform a String data using Base64 algorithm and then de-compress the result into another String.
      void compress​(java.io.OutputStream toStream, java.lang.String fromString, int estimateRatio)
      Compress data from a String to an OutputStream.
      byte[] compress​(java.lang.String fromString, int estimateRatio)
      Compress data from an String and returns a byte array for the result.
      java.lang.String compressAndBase64​(java.lang.String fromString, int estimateRatio)
      Compress a String data and then transform the result into another String using Base64 algorithm.
      java.lang.String decompress​(byte[] fromData, int estimateRatio)
      De-compress a byte array of data and returns the result as a String.
      java.lang.String decompress​(java.io.InputStream fromStream, int bufferSize)
      De-compress data from an InputStream and returns the result as a String.
      static GZIPHelper getInstance()
      Sigleton entry.
      • Methods inherited from class java.lang.Object

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

      • MAGIC_HEADER

        public static final java.lang.String MAGIC_HEADER
        The magic header for Ziped and Base64ed string.
        See Also:
        Constant Field Values
      • ESTIMATE_XML_STATUS_COMPRESS_RATIO

        public static final int ESTIMATE_XML_STATUS_COMPRESS_RATIO
        The estimate compress ratio for XML status.
        See Also:
        Constant Field Values
      • ESTIMATE_XML_STATUS_COMPRESS_RATIO_DELTA

        public static final int ESTIMATE_XML_STATUS_COMPRESS_RATIO_DELTA
        The estimate variation value of the compression ration.
        See Also:
        Constant Field Values
    • Constructor Detail

      • GZIPHelper

        public GZIPHelper()
    • Method Detail

      • getInstance

        public static GZIPHelper getInstance()
        Sigleton entry.
        Returns:
        GZIPHelper The GZIPHelper instance.
      • compress

        public void compress​(java.io.OutputStream toStream,
                             java.lang.String fromString,
                             int estimateRatio)
        Compress data from a String to an OutputStream.
        Parameters:
        toStream - The target OutputStream.
        fromString - The String data to be compressed.
        estimateRatio - The estimated ratio of this compression operation.
      • compress

        public byte[] compress​(java.lang.String fromString,
                               int estimateRatio)
        Compress data from an String and returns a byte array for the result.
        Parameters:
        fromString - The String data to be compressed.
        estimateRatio - The estimated ratio of this compression operation.
        Returns:
        a byte array holding the compressed result.
      • compressAndBase64

        public java.lang.String compressAndBase64​(java.lang.String fromString,
                                                  int estimateRatio)
        Compress a String data and then transform the result into another String using Base64 algorithm.
        Parameters:
        fromString - The String data to be compressed and transformed.
        estimateRatio - The estimated ratio of the compression operation.
        Returns:
        a String holding the result of compression and transformation.
      • base64AndDecompress

        public java.lang.String base64AndDecompress​(java.lang.String fromString,
                                                    int estimateRatio)
        De-transform a String data using Base64 algorithm and then de-compress the result into another String. It is the reverse process of compressAndBase64(java.lang.String, int) method.
        Parameters:
        fromString - The String data to be transformed and de-compressed.
        estimateRatio - The estimated ratio of the compression operation.
        Returns:
        a String data holding the result of de-transformation and de-compression.
      • decompress

        public java.lang.String decompress​(byte[] fromData,
                                           int estimateRatio)
        De-compress a byte array of data and returns the result as a String.
        Parameters:
        fromData - The byte array of data to be de-compressed.
        estimateRatio - The estimated ratio of the compression operation.
        Returns:
        a String holding the result of de-compression.
      • decompress

        public java.lang.String decompress​(java.io.InputStream fromStream,
                                           int bufferSize)
        De-compress data from an InputStream and returns the result as a String.
        Parameters:
        fromStream - The InputStream to be de-compressed.
        bufferSize - The estimate size of the StringBuffer to be allocated to hold the result.
        Returns:
        a String holding the result of de-compression.