Class AsciiCompressor

java.lang.Object
com.dannemann.stringcompressor.AsciiCompressor
Direct Known Subclasses:
FiveBitAsciiCompressor, FourBitAsciiCompressor, SixBitAsciiCompressor

public abstract class AsciiCompressor extends Object
  • Field Details

    • supportedCharset

      protected final byte[] supportedCharset
    • preserveOriginal

      protected boolean preserveOriginal
      To avoid duplicating strings and save memory, the compressor will modify the original input string, encoding it and making it unusable. To avoid this behavior and compress a copy of the original, set this to true.
    • throwException

      protected boolean throwException
      Throw validation exceptions while compressing. Useful for debug but not recommended for production.
  • Constructor Details

    • AsciiCompressor

      public AsciiCompressor(byte[] supportedCharset)
  • Method Details

    • compress

      public abstract byte[] compress(byte[] str)
    • decompress

      public abstract byte[] decompress(byte[] compressed)
      Restores the original string from data compressed by compress(byte[]).
      Parameters:
      compressed - The compressed string byte array.
      Returns:
      A decompressed string byte array.
    • validateSupportedCharset

      protected abstract void validateSupportedCharset(byte[] supportedCharset)
    • standardCharsetValidation

      protected void standardCharsetValidation(byte[] supportedCharset, int numBits)
    • encode

      protected void encode(byte[] string, int len)
    • setPreserveOriginal

      public void setPreserveOriginal(boolean preserveOriginal)
    • setThrowException

      public void setThrowException(boolean throwException)