Package com.dannemann.stringcompressor
Class AsciiCompressor
java.lang.Object
com.dannemann.stringcompressor.AsciiCompressor
- Direct Known Subclasses:
FiveBitAsciiCompressor,FourBitAsciiCompressor,SixBitAsciiCompressor
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanTo avoid duplicating strings and save memory, the compressor will modify the original input string, encoding it and making it unusable.protected final byte[]protected booleanThrow validation exceptions while compressing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract byte[]compress(byte[] str) abstract byte[]decompress(byte[] compressed) Restores the original string from data compressed bycompress(byte[]).protected voidencode(byte[] string, int len) voidsetPreserveOriginal(boolean preserveOriginal) voidsetThrowException(boolean throwException) protected voidstandardCharsetValidation(byte[] supportedCharset, int numBits) protected abstract voidvalidateSupportedCharset(byte[] supportedCharset)
-
Field Details
-
supportedCharset
protected final byte[] supportedCharset -
preserveOriginal
protected boolean preserveOriginalTo 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 totrue. -
throwException
protected boolean throwExceptionThrow 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 bycompress(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)
-