Package com.dannemann.stringcompressor
Class SixBitAsciiCompressor
java.lang.Object
com.dannemann.stringcompressor.AsciiCompressor
com.dannemann.stringcompressor.SixBitAsciiCompressor
Performs 6-bit-per-ASCII-character encoding and decoding.
Compression rate: 25%
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]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', '[', ']', '_', '{', '}'static final byte[]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', '{', '}'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 6-bit character set (DEFAULT_6BIT_CHARSET).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.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.SixBitAsciiCompressor(byte[] supportedCharset) Creates a new compressor instance with a user defined 6-bit character set.SixBitAsciiCompressor(byte[] supportedCharset, boolean throwException) Creates a new compressor instance with a user defined 6-bit character set and configurable exception-throwing behavior.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. -
Method Summary
Modifier and TypeMethodDescriptionfinal byte[]compress(byte[] string) Packs characters into chunks of 6 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_6BIT_CHARSET
public static final byte[] DEFAULT_6BIT_CHARSET6-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_LOWERCASE6-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.throwExceptionisfalse) and byte array data preservation (AsciiCompressor.preserveOriginalisfalse). -
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.throwExceptionisfalse) and byte array data preservation (AsciiCompressor.preserveOriginalisfalse).- Parameters:
supportedCharset- The custom set of supported characters. SeeDEFAULT_6BIT_CHARSETfor 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.preserveOriginalisfalse).- Parameters:
throwException- Iftrue, 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.preserveOriginalisfalse).- Parameters:
supportedCharset- The custom set of supported characters. SeeDEFAULT_6BIT_CHARSETfor an example of how to define it.throwException- Iftrue, 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- 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:
-
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. SeeDEFAULT_6BIT_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 6 bits. Supports a set of 64 different characters (000000 to 111111).
Compression rate: 25%
See
DEFAULT_6BIT_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
-