Reputation: 526
I want to compress any string, if it has more than 50chars in it. If char size if less than 50, then let it be untouched, else it has to be compressed to required limit (50).
I will be inserting this compressed/uncompressed output in DB. So, while fetching back the data from DB, i want the compressed string to be easily differentiated from uncompressed (some common pattern for compressed string).
Please suggest some best compressing lib/algorithm ?
Upvotes: 0
Views: 414
Reputation: 136162
I would use Inflater / Deflater from java.util.zip package. They use native ZLIB compression library and are very efficient. It's easy to differentiate compressed text from uncompressed - try to decompress and you will get an exception if it's a plain text
Upvotes: 0
Reputation: 7854
Please suggest some best compressing lib/algorithm ?
there is no such algorithm or library so that any string can be compressed to a given max characters (e.g. 50) without any loss of information.
Upvotes: 1
Reputation: 88488
If your compression is allowed to be lossy, you can use the abbreviate function from Apache Commons lang
Upvotes: 0