Class CompressionTools


  • public class CompressionTools
    extends java.lang.Object
    Simple utility class providing static methods to compress and decompress binary data for stored fields. This class uses java.util.zip.Deflater and Inflater classes to compress and decompress.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] compress​(byte[] value)
      Compresses all bytes in the array, with default BEST_COMPRESSION level
      static byte[] compress​(byte[] value, int offset, int length)
      Compresses the specified byte range, with default BEST_COMPRESSION level
      static byte[] compress​(byte[] value, int offset, int length, int compressionLevel)
      Compresses the specified byte range using the specified compressionLevel (constants are defined in java.util.zip.Deflater).
      static byte[] compressString​(java.lang.String value)
      Compresses the String value, with default BEST_COMPRESSION level
      static byte[] compressString​(java.lang.String value, int compressionLevel)
      Compresses the String value using the specified compressionLevel (constants are defined in java.util.zip.Deflater).
      static byte[] decompress​(byte[] value)
      Decompress the byte array previously returned by compress
      static byte[] decompress​(byte[] value, int offset, int length)
      Decompress the byte array previously returned by compress
      static byte[] decompress​(BytesRef bytes)
      Decompress the byte array previously returned by compress (referenced by the provided BytesRef)
      static java.lang.String decompressString​(byte[] value)
      Decompress the byte array previously returned by compressString back into a String
      static java.lang.String decompressString​(byte[] value, int offset, int length)
      Decompress the byte array previously returned by compressString back into a String
      static java.lang.String decompressString​(BytesRef bytes)
      Decompress the byte array (referenced by the provided BytesRef) previously returned by compressString back into a String
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • compress

        public static byte[] compress​(byte[] value,
                                      int offset,
                                      int length,
                                      int compressionLevel)
        Compresses the specified byte range using the specified compressionLevel (constants are defined in java.util.zip.Deflater).
      • compress

        public static byte[] compress​(byte[] value,
                                      int offset,
                                      int length)
        Compresses the specified byte range, with default BEST_COMPRESSION level
      • compress

        public static byte[] compress​(byte[] value)
        Compresses all bytes in the array, with default BEST_COMPRESSION level
      • compressString

        public static byte[] compressString​(java.lang.String value)
        Compresses the String value, with default BEST_COMPRESSION level
      • compressString

        public static byte[] compressString​(java.lang.String value,
                                            int compressionLevel)
        Compresses the String value using the specified compressionLevel (constants are defined in java.util.zip.Deflater).
      • decompress

        public static byte[] decompress​(BytesRef bytes)
                                 throws java.util.zip.DataFormatException
        Decompress the byte array previously returned by compress (referenced by the provided BytesRef)
        Throws:
        java.util.zip.DataFormatException
      • decompress

        public static byte[] decompress​(byte[] value)
                                 throws java.util.zip.DataFormatException
        Decompress the byte array previously returned by compress
        Throws:
        java.util.zip.DataFormatException
      • decompress

        public static byte[] decompress​(byte[] value,
                                        int offset,
                                        int length)
                                 throws java.util.zip.DataFormatException
        Decompress the byte array previously returned by compress
        Throws:
        java.util.zip.DataFormatException
      • decompressString

        public static java.lang.String decompressString​(byte[] value)
                                                 throws java.util.zip.DataFormatException
        Decompress the byte array previously returned by compressString back into a String
        Throws:
        java.util.zip.DataFormatException
      • decompressString

        public static java.lang.String decompressString​(byte[] value,
                                                        int offset,
                                                        int length)
                                                 throws java.util.zip.DataFormatException
        Decompress the byte array previously returned by compressString back into a String
        Throws:
        java.util.zip.DataFormatException
      • decompressString

        public static java.lang.String decompressString​(BytesRef bytes)
                                                 throws java.util.zip.DataFormatException
        Decompress the byte array (referenced by the provided BytesRef) previously returned by compressString back into a String
        Throws:
        java.util.zip.DataFormatException