Package com.dannemann.stringcompressor
Class FiveBitAsciiCompressor
java.lang.Object
com.dannemann.stringcompressor.AsciiCompressor
com.dannemann.stringcompressor.FiveBitAsciiCompressor
Performs 5-bit-per-ASCII-character encoding and decoding.
Compression rate: 38%
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]5-bit character set supported by default (ordered by ASCII): ' ', '\'', ',', '-', '.', '@', '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'static final byte[]5-bit lowercase character set supported by default (ordered by ASCII): ' ', '\'', ',', '-', '.', '@', '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'Fields inherited from class com.dannemann.stringcompressor.AsciiCompressor
PRESERVE_ORIGINAL_DEFAULT, preserveOriginal, supportedCharset, THROW_EXCEPTION_DEFAULT, throwException -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new compressor instance using the default 5-bit character set (DEFAULT_5BIT_CHARSET).FiveBitAsciiCompressor(boolean throwException) Creates a new compressor instance using the default 5-bit character set (DEFAULT_5BIT_CHARSET) and with a configurable exception-throwing behavior.FiveBitAsciiCompressor(boolean throwException, boolean preserveOriginal) Creates a new compressor instance using the default 5-bit character set (DEFAULT_5BIT_CHARSET), with configurable exception-throwing behavior and byte array data preservation.FiveBitAsciiCompressor(byte[] supportedCharset) Creates a new compressor instance with a user defined 5-bit character set.FiveBitAsciiCompressor(byte[] supportedCharset, boolean throwException) Creates a new compressor instance with a user defined 5-bit character set and configurable exception-throwing behavior.FiveBitAsciiCompressor(byte[] supportedCharset, boolean throwException, boolean preserveOriginal) Creates a new compressor instance with a user defined 5-bit character set, configurable exception-throwing behavior, and byte array data preservation. -
Method Summary
Modifier and TypeMethodDescriptionfinal byte[]compress(byte[] string) Packs characters into chunks of 5 bits.byte[]Overloaded version ofcompress(byte[]).final byte[]decompress(byte[] compressed) Restores the original string from data compressed bycompress(byte[]).protected voidvalidateSupportedCharset(byte[] supportedCharset) Methods inherited from class com.dannemann.stringcompressor.AsciiCompressor
encode, getBytes, getString, getSupportedCharset, isPreserveOriginal, isThrowException, standardCharsetValidation
-
Field Details
-
DEFAULT_5BIT_CHARSET
public static final byte[] DEFAULT_5BIT_CHARSET5-bit character set supported by default (ordered by ASCII): ' ', '\'', ',', '-', '.', '@', '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_5BIT_CHARSET_LOWERCASE
public static final byte[] DEFAULT_5BIT_CHARSET_LOWERCASE5-bit lowercase character set supported by default (ordered by ASCII): ' ', '\'', ',', '-', '.', '@', '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
-
FiveBitAsciiCompressor
public FiveBitAsciiCompressor()Creates a new compressor instance using the default 5-bit character set (DEFAULT_5BIT_CHARSET). Uses default settings for exception throwing (AsciiCompressor.throwExceptionisfalse) and byte array data preservation (AsciiCompressor.preserveOriginalisfalse). -
FiveBitAsciiCompressor
public FiveBitAsciiCompressor(byte[] supportedCharset) Creates a new compressor instance with a user defined 5-bit character set. Uses default settings for exception throwing (AsciiCompressor.throwExceptionisfalse) and byte array data preservation (AsciiCompressor.preserveOriginalisfalse).- Parameters:
supportedCharset- The custom set of supported characters. SeeDEFAULT_5BIT_CHARSETfor an example of how to define it.- See Also:
-
FiveBitAsciiCompressor
public FiveBitAsciiCompressor(boolean throwException) Creates a new compressor instance using the default 5-bit character set (DEFAULT_5BIT_CHARSET) and with a configurable exception-throwing behavior. Uses default setting for byte array data preservation (AsciiCompressor.preserveOriginalisfalse).- Parameters:
throwException- Iftrue, throws an exception on unsupported characters; otherwise, silently ignores them.- See Also:
-
FiveBitAsciiCompressor
public FiveBitAsciiCompressor(byte[] supportedCharset, boolean throwException) Creates a new compressor instance with a user defined 5-bit character set and configurable exception-throwing behavior. Uses default setting for byte array data preservation (AsciiCompressor.preserveOriginalisfalse).- Parameters:
supportedCharset- The custom set of supported characters. SeeDEFAULT_5BIT_CHARSETfor an example of how to define it.throwException- Iftrue, throws an exception on unsupported characters; otherwise, silently ignores them.- See Also:
-
FiveBitAsciiCompressor
public FiveBitAsciiCompressor(boolean throwException, boolean preserveOriginal) Creates a new compressor instance using the default 5-bit character set (DEFAULT_5BIT_CHARSET), with configurable exception-throwing behavior and byte array data preservation.- Parameters:
throwException- Iftrue, throws an exception on unsupported characters; otherwise, silently ignores them.preserveOriginal- Iftrue, preserves the original input byte array by working on a copy; otherwise, modifies it directly.- See Also:
-
FiveBitAsciiCompressor
public FiveBitAsciiCompressor(byte[] supportedCharset, boolean throwException, boolean preserveOriginal) Creates a new compressor instance with a user defined 5-bit character set, configurable exception-throwing behavior, and byte array data preservation.- Parameters:
supportedCharset- The custom set of supported characters. SeeDEFAULT_5BIT_CHARSETfor an example of how to define it.throwException- Iftrue, throws an exception on unsupported characters; otherwise, silently ignores them.preserveOriginal- Iftrue, 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 5 bits. Supports a set of 32 different characters (00000 to 11111).
Compression rate: 38%
See
DEFAULT_5BIT_CHARSETfor the default set of supported characters. To use a custom character set, refer to any constructor that accepts thebyte[] supportedCharsetparameter.- Specified by:
compressin classAsciiCompressor- Parameters:
string- String byte array to be compressed.- Returns:
- A compressed byte array.
- Throws:
NullPointerException- Ifstringis null.
-
compress
Overloaded version of
compress(byte[]).Whenever possible, use
compress(byte[])and avoid string instantiation.- Specified by:
compressin classAsciiCompressor
-
decompress
public final byte[] decompress(byte[] compressed) Restores the original string from data compressed bycompress(byte[]).- Specified by:
decompressin classAsciiCompressor- Parameters:
compressed- The compressed string byte array.- Returns:
- A decompressed string byte array.
-
validateSupportedCharset
protected void validateSupportedCharset(byte[] supportedCharset) - Specified by:
validateSupportedCharsetin classAsciiCompressor
-