-
Notifications
You must be signed in to change notification settings - Fork 4
Using Qat‐Java in a Maven Project
mulugetam edited this page Aug 18, 2023
·
4 revisions
-
Create a directory structure for your project:
qat_java_example/ ├── src/ │ ├── main/ │ │ └── java/ │ │ └── com/ │ │ └── example/ │ │ └── ByteArrayExample.java │ └── test/ │ └── java/ └── pom.xml
-
Create
ByteArrayExample.java
:Inside the
src/main/java/com/example
directory, create a file namedByteArrayExample.java
with 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 pom.xml:
In the root directory of your project, create a file named
pom.xml
with the following content. The file describes your project and its dependencies.<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>qat-java-example</artifactId> <version>1.0</version> <packaging>jar</packaging> <properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>com.intel.qat</groupId> <artifactId>qat-java</artifactId> <version>1.0.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.4.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
-
Build and Run: Open a terminal, navigate to your project directory, and run the following commands:
mvn clean install java -cp target/qat-java-example-1.0.jar com.example.ByteArrayExample
If successful, you should see the below output in your terminal:
Decompressed data: The quick brown fox jumps over the lazy dog.