org.xerial.snappy.Snappy Example

Q

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

✍: FYIcenter.com

A

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

Here is an example Java program, HelloSnappy.java:

// HelloSnappy.java
// Copyright (c) FYIcenter.com

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");

    System.out.println(result);
  }
}

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

fyicenter$ java -cp snappy-java-1.1.8.4.jar HelloSnappy.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, 780🔥, 0💬