org.xerial.snappy.Snappy Example


How to use org.xerial.snappy.Snappy class?



org.xerial.snappy.Snappy class allows you to compress and decompress byte arrays.

Here is an example Java program,

// Copyright (c)

import org.xerial.snappy.Snappy;
public class HelloSnappy {
  public static void main(String[] args) throws Exception {
    String input = "Hello snappy-java! Snappy-java is a JNI-based wrapper"
      + " of Snappy, a fast compresser/decompresser.";

    byte[] original = input.getBytes("UTF-8");
    byte[] compressed = Snappy.compress(original);
    byte[] uncompressed = Snappy.uncompress(compressed);
    String result = new String(uncompressed, "UTF-8");


Run this Java program with the Snappy-Java JAR file:

fyicenter$ java -cp snappy-java-

Hello snappy-java! Snappy-java is a JNI-based wrapper of Snappy, a fast compresser/decompresser.

The Java program compress and decompress a message correctly.


Snappy-Java - Compress and Decompress Files

Using Snappy-Java Library

Using Snappy-Java Library

⇑⇑ Snappy-Java - Compresser and Decompresser

2021-08-01, 691🔥, 0💬