Class SixBitAsciiCompressor

java.lang.Object
com.dannemann.stringcompressor.AsciiCompressor
com.dannemann.stringcompressor.SixBitAsciiCompressor

public class SixBitAsciiCompressor extends AsciiCompressor

Performs 6-bit-per-ASCII-character encoding and decoding.

Compression rate: 25%

  • Field Details

    • DEFAULT_6BIT_CHARSET

      public static final byte[] DEFAULT_6BIT_CHARSET
      6-bit character set supported by default (ordered by ASCII): ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', ']', '_', '{', '}'
    • DEFAULT_6BIT_CHARSET_LOWERCASE

      public static final byte[] DEFAULT_6BIT_CHARSET_LOWERCASE
      6-bit lowercase character set supported by default (ordered by ASCII): ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', '[', ']', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '}'
  • Constructor Details

    • SixBitAsciiCompressor

      public SixBitAsciiCompressor()
      Creates a new compressor instance using the default 6-bit character set (DEFAULT_6BIT_CHARSET). Uses default settings for exception throwing (AsciiCompressor.throwException is false) and byte array data preservation (AsciiCompressor.preserveOriginal is false).
    • SixBitAsciiCompressor

      public SixBitAsciiCompressor(byte[] supportedCharset)
      Creates a new compressor instance with a user defined 6-bit character set. Uses default settings for exception throwing (AsciiCompressor.throwException is false) and byte array data preservation (AsciiCompressor.preserveOriginal is false).
      Parameters:
      supportedCharset - The custom set of supported characters. See DEFAULT_6BIT_CHARSET for an example of how to define it.
      See Also:
    • SixBitAsciiCompressor

      public SixBitAsciiCompressor(boolean throwException)
      Creates a new compressor instance using the default 6-bit character set (DEFAULT_6BIT_CHARSET) and with a configurable exception-throwing behavior. Uses default setting for byte array data preservation (AsciiCompressor.preserveOriginal is false).
      Parameters:
      throwException - If true, throws an exception on unsupported characters; otherwise, silently ignores them.
      See Also:
    • SixBitAsciiCompressor

      public SixBitAsciiCompressor(byte[] supportedCharset, boolean throwException)
      Creates a new compressor instance with a user defined 6-bit character set and configurable exception-throwing behavior. Uses default setting for byte array data preservation (AsciiCompressor.preserveOriginal is false).
      Parameters:
      supportedCharset - The custom set of supported characters. See DEFAULT_6BIT_CHARSET for an example of how to define it.
      throwException - If true, throws an exception on unsupported characters; otherwise, silently ignores them.
      See Also:
    • SixBitAsciiCompressor

      public SixBitAsciiCompressor(boolean throwException, boolean preserveOriginal)
      Creates a new compressor instance using the default 6-bit character set (DEFAULT_6BIT_CHARSET), with configurable exception-throwing behavior and byte array data preservation.
      Parameters:
      throwException - If true, throws an exception on unsupported characters; otherwise, silently ignores them.
      preserveOriginal - If true, preserves the original input byte array by working on a copy; otherwise, modifies it directly.
      See Also:
    • SixBitAsciiCompressor

      public SixBitAsciiCompressor(byte[] supportedCharset, boolean throwException, boolean preserveOriginal)
      Creates a new compressor instance with a user defined 6-bit character set, configurable exception-throwing behavior, and byte array data preservation.
      Parameters:
      supportedCharset - The custom set of supported characters. See DEFAULT_6BIT_CHARSET for an example of how to define it.
      throwException - If true, throws an exception on unsupported characters; otherwise, silently ignores them.
      preserveOriginal - If true, preserves the original input byte array by working on a copy; otherwise, modifies it directly.
      See Also:
  • Method Details

    • compress

      public final byte[] compress(byte[] string)

      Packs characters into chunks of 6 bits. Supports a set of 64 different characters (000000 to 111111).

      Compression rate: 25%

      See DEFAULT_6BIT_CHARSET for the default set of supported characters. To use a custom character set, refer to any constructor that accepts the byte[] supportedCharset parameter.

      Specified by:
      compress in class AsciiCompressor
      Parameters:
      string - String byte array to be compressed.
      Returns:
      A compressed byte array.
      Throws:
      NullPointerException - If string is null.
    • compress

      public byte[] compress(String string)

      Overloaded version of compress(byte[]).

      Whenever possible, use compress(byte[]) and avoid string instantiation.

      Specified by:
      compress in class AsciiCompressor
    • decompress

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

      protected void validateSupportedCharset(byte[] supportedCharset)
      Specified by:
      validateSupportedCharset in class AsciiCompressor