Class Zlib


  • public class Zlib
    extends Object
    Compression/de-compression support.
    Author:
    Martin Lindström (martin@idsec.se), Henrik Bengtsson (extern.henrik.bengtsson@digg.se), Henric Norlander (extern.henric.norlander@digg.se)
    • Method Detail

      • compress

        public static byte[] compress​(byte[] data)
        Compresses the supplied data.
        Parameters:
        data - the data to compress
        Returns:
        the compressed data
      • decompress

        public static byte[] decompress​(byte[] data,
                                        boolean requireCompressed)
                                 throws ZipException
        De-compresses the supplied data.

        If requireCompressed is true we require the input data to contain a ZLIB header (i.e., be compressed using the ZLIB algorithm). If it is false and a ZipException is caught, the input data is assumed to be un-compressed, and the method will return data.

        Parameters:
        data - the data to de-compress
        requireCompressed - boolean telling whether we require the supplied data to be compressed
        Returns:
        the de-compressed data
        Throws:
        ZipException - if requireCompressed is true and an inflate error occurs
      • isCompressed

        public static boolean isCompressed​(byte[] data)
        Predicate that checks if the supplied data is compressed using the ZLIB algorithm.
        Parameters:
        data - the data to check
        Returns:
        true if the supplied data is compressed and false otherwise