简体   繁体   中英

Compress a very large string to smallest string as possible in java

I want to Compress very large string to smallest string as possible, because i want to send it by sms.

i am currently using this Encoding Decoding methods but it gives me a very large Cipher Text

String LongText="Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! " + "Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! " + "Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! " + "Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! " + "Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! Welcome! "

public byte[] Encoding(String PlainText)
{
    byte[] encodeValue = Base64.encode(PlainText.getBytes(), Base64.DEFAULT);
    return encodeValue;
}

public String Decoding(byte[] CipherText)
{
    byte[] decodeValue = Base64.decode(CipherText, Base64.DEFAULT);
    return new String(decodeValue);
}

You could use Huffman compression but that of course means you have to compress at sender and decompress at receiver side. The more common characters there are in the message, the better the compression rate will be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM