Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
Snappy-Java - Compress and Decompress Files
How to Compress and Decompress Files with Snappy-Java?
✍: FYIcenter.com
If you want to compress or decompress files with Snappy-Java, you can write 2 Java programs as shown in this tutorial.
The first program compresses a given file, CompressFIle.java:
// CompressFIle.java
// Copyright (c) FYIcenter.com
import org.xerial.snappy.Snappy;
import java.nio.file.*;
public class CompressFIle {
public static void main(String[] args) throws Exception {
Path input = Paths.get(args[0]);
byte[] uncompressed = Files.readAllBytes(input);
byte[] compressed = Snappy.compress(uncompressed);
Path output = Paths.get(args[1]);
Files.write(output, compressed);
}
}
The second program compresses a given file, DecompressFIle.java:
// DecompressFile.java
// Copyright (c) FYIcenter.com
import org.xerial.snappy.Snappy;
import java.nio.file.*;
public class DecompressFile {
public static void main(String[] args) throws Exception {
Path input = Paths.get(args[0]);
byte[] compressed = Files.readAllBytes(input);
byte[] uncompressed = Snappy.uncompress(compressed);
Path output = Paths.get(args[1]);
Files.write(output, uncompressed);
}
}
Here is how to compress a file:
fyicenter$ java -cp snappy-java-1.1.8.4.jar CompressFile.java \ HelloSnappy.java HelloSnappy.java.spz fyicenter$ ls -l HelloSnappy.* 551 Jul 10 13:42 HelloSnappy.java 404 Jul 10 14:48 HelloSnappy.java.spz
Here is how to decompress a file:
fyicenter$ java -cp snappy-java-1.1.8.4.jar DecompressFile.java \ HelloSnappy.java.spz HelloSnappy.java.txt fyicenter$ ls -l HelloSnappy.* 551 Jul 10 13:42 HelloSnappy.java 404 Jul 10 14:48 HelloSnappy.java.spz 551 Jul 10 14:51 HelloSnappy.java.txt
⇒ Snappy-Java - Compresser and Decompresser
2021-07-13, ∼2188🔥, 0💬
Popular Posts:
JDK 11 jdk.jcmd.jmod is the JMOD file for JDK 11 JCmd tool, which can be invoked by the "jcmd" comma...
The Web Services Description Language for Java Toolkit (WSDL4J), Release 1.6.2, allows the creation,...
Java Cryptography Extension 1.6 JAR File Size and Download Location: File name: jce.jar, jce-1.6.jar...
JLayer is a library that decodes/plays/converts MPEG 1/2/2.5 Layer 1/2/3 (i.e. MP3) in real time for...
JDK 11 java.naming.jmod is the JMOD file for JDK 11 Naming module. JDK 11 Naming module compiled cla...