-
Notifications
You must be signed in to change notification settings - Fork 4
Using Qat‐Java
mulugetam edited this page Aug 18, 2023
·
2 revisions
-
Create a directory for your example project:
mkdir -p my_example_project
-
Navigate to your project directory and create a directory for your package.
cd my_example_project mkdir -p com/example
-
Download the
qat-java-1.0.0.jar
from maven central.wget https://repo1.maven.org/maven2/com/intel/qat/qat-java/1.0.0/qat-java-1.0.0.jar
-
Create a
ByteArrayExample.java
file with the following content in thecom/example
directory:package com.example; import com.intel.qat.QatException; import com.intel.qat.QatZipper; public class ByteArrayExample { public static void main(String[] args) { try { String inputStr = "The quick brown fox jumps over the lazy dog."; byte[] input = inputStr.getBytes(); // Create a QatZipper object QatZipper qzip = new QatZipper(); // Create a buffer with enough size for compression byte[] compressedData = new byte[qzip.maxCompressedLength(input.length)]; // Compress the bytes int compressedSize = qzip.compress(input, compressedData); // Decompress the bytes into a String byte[] decompressedData = new byte[input.length]; int decompressedSize = qzip.decompress(compressedData, decompressedData); // Release resources qzip.end(); // Convert the bytes into a String String outputStr = new String(decompressedData, 0, decompressedSize); System.out.println("Decompressed data: " + outputStr); } catch (QatException e) { e.printStackTrace(); } } }
-
Compile the
ByteArrayExample.java
run the following command:javac -cp qat-java-1.0.0.jar com/example/ByteArrayExample.java
-
Run your example:
java -cp .:qat-java-1.0.0.jar com.example.ByteArrayExample
Output:
Decompressed data: The quick brown fox jumps over the lazy dog.