-
Notifications
You must be signed in to change notification settings - Fork 5
Using Qat‐Java in a Gradle Project
mulugetam edited this page Aug 18, 2023
·
7 revisions
-
Create a directory structure for your project:
qat_java_example/ ├── src/ │ ├── main/ │ │ └── java/ │ │ └── com/ │ │ └── example/ │ │ └── ByteArrayExample.java │ └── test/ └── build.gradle -
Create
ByteArrayExample.java:Inside the
src/main/java/com/exampledirectory, create a file namedByteArrayExample.javawith the following content.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(); } } } -
Create build.gradle:
In the root directory of your project, create a file named
build.gradlewith the following content. The file describes your project and its dependencies.apply plugin: 'application' repositories { mavenCentral() } dependencies { implementation 'com.intel.qat:qat-java:1.0.0' } application { mainClassName = 'com.example.ByteArrayExample' } -
Build and Run:
Open a terminal, navigate to your project directory, and run the following command:
gradle wrapperTo build and run, use the following commands:
./gradlew build ./gradlew runIf successful, you should see the below output in your terminal:
Decompressed data: The quick brown fox jumps over the lazy dog.