Skip to content

Commit

Permalink
Add factory to create a (de)compressor based on native availability
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo committed Jul 19, 2024
1 parent 3b4a4b1 commit 4098469
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
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();
}
}

0 comments on commit 4098469

Please sign in to comment.