Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add factory to create a (de)compressor based on native availability #203

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/io/airlift/compress/v2/lz4/Lz4Compressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public sealed interface Lz4Compressor
permits Lz4JavaCompressor, Lz4NativeCompressor
{
int compress(MemorySegment input, MemorySegment output);

static Lz4Compressor create()
{
if (Lz4NativeCompressor.isEnabled()) {
return new Lz4NativeCompressor();
}
return new Lz4JavaCompressor();
}
}
8 changes: 8 additions & 0 deletions src/main/java/io/airlift/compress/v2/lz4/Lz4Decompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public sealed interface Lz4Decompressor
permits Lz4JavaDecompressor, Lz4NativeDecompressor
{
int decompress(MemorySegment input, MemorySegment output);

static Lz4Decompressor create()
{
if (Lz4NativeDecompressor.isEnabled()) {
return new Lz4NativeDecompressor();
}
return new Lz4JavaDecompressor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public sealed interface SnappyCompressor
permits SnappyJavaCompressor, SnappyNativeCompressor
{
int compress(MemorySegment input, MemorySegment output);

static SnappyCompressor create()
{
if (SnappyNativeCompressor.isEnabled()) {
return new SnappyNativeCompressor();
}
return new SnappyJavaCompressor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ public sealed interface SnappyDecompressor
permits SnappyJavaDecompressor, SnappyNativeDecompressor
{
int getUncompressedLength(byte[] compressed, int compressedOffset);

static SnappyDecompressor create()
{
if (SnappyNativeDecompressor.isEnabled()) {
return new SnappyNativeDecompressor();
}
return new SnappyJavaDecompressor();
}
}
8 changes: 8 additions & 0 deletions src/main/java/io/airlift/compress/v2/zstd/ZstdCompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ public interface ZstdCompressor
extends Compressor
{
int compress(MemorySegment input, MemorySegment output);

static ZstdCompressor create()
{
if (ZstdNativeCompressor.isEnabled()) {
return new ZstdNativeCompressor();
}
return new ZstdJavaCompressor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ public interface ZstdDecompressor
extends Decompressor
{
long getDecompressedSize(byte[] input, int offset, int length);

static ZstdDecompressor create()
{
if (ZstdNativeDecompressor.isEnabled()) {
return new ZstdNativeDecompressor();
}
return new ZstdJavaDecompressor();
}
}
Loading