Lzstring4j
LZ-based compression algorithm for Java
Install / Use
/learn @diogoduailibe/Lzstring4jREADME
lzstring4j - LZString for Java
lzstring4j is an easy to use implementation of JavaScript LZString Library for Java.
This idea is inspired by lz-string-java.
Features:
- Based on JavaScript LZString Library (version 1.3.3)
- UTF-16 compression
- Base64 compression
- Interoperable with the JavaScript Library through the UTF-16 compression methods (Java Server -> JS on Web or Node.js server -> Java Client/Android) thanks to this post.
How to use
Using lzstring4j is quite simple. But lets see:
Checkout and compile the project:
git clone https://github.com/diogoduailibe/lzstring4j.git
cd lzstring4j
mvn clean install
Then, import in your project using maven dependecy
<dependency>
<groupId>com.github.diogoduailibe</groupId>
<artifactId>lzstring4j</artifactId>
<version>1.3.3</version>
</dependency>
Afterwards, you'll be able to use this library:
Normal Compression and Decompression:
// Normal Compression and Decompression
String test = "Lets see how much we can compress this string!";
String output = LZString.compress(test);
System.out.println("Compressed: " + output);
String decompressed = LZString.decompress(output);
System.out.println("Decompressed: " + decompressed);
UTF-16 Compression and Decompression:
//UTF-16 Compression and Decompression
String testUTF16 = "Lets see how much we can compress this string!";
String outputUTF16 = LZString.compressToUTF16(testUTF16);
System.out.println("Compressed: " + outputUTF16);
String decompressedUTF16 = LZString.decompressFromUTF16(outputUTF16);
System.out.println("Decompressed: " + decompressedUTF16);
Base64 Compression and Decompression:
//Base64 Compression and Decompression
String testBase64 = "Lets see how much we can compress this string!";
String outputBase64 = LZString.compressToBase64(testBase64);
System.out.println("Compressed: " + outputBase64);
String decompressedBase64 = LZString.decompressFromBase64(outputBase64);
System.out.println("Decompressed: " + decompressedBase64);
Tests
In order to run JUnit tests, just run:
mvn test
You'll see tests for Normal, UTF-16 and Base64 compression and decompression.
Checkout
git clone https://github.com/diogoduailibe/lzstring4j.git
Building
to build a jar-file:
cd $PATH_TO_LZSTRING4J
mvn clean package
ls target/lzstring4j-<version>.jar
You'll find it in target path
Bugs
Please report any bugs feature requests to the Github issue tracker
Frameworks
This Library was designed with portability in mind.
- Android is fully supported.
- JRE is fully supported.
TODO
- Improve code to execute more efficiently
- Update to version 1.4.4
- More tests...
CONTRIBUTORS (Thanks to all, by the way!)
- diogoduailibe
- helloanand
- cloudeecn
License - the boring stuff...
See LICENSE file.
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
