-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bridge between aircompressor v1 and v2
Additionally: seal interfaces and add factory methods
- Loading branch information
Showing
37 changed files
with
879 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public interface Compressor | ||
{ | ||
int maxCompressedLength(int uncompressedSize); | ||
|
||
/** | ||
* @return number of bytes written to the output | ||
*/ | ||
int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength); | ||
|
||
void compress(ByteBuffer input, ByteBuffer output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public interface Decompressor | ||
{ | ||
/** | ||
* @return number of bytes written to the output | ||
*/ | ||
int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) | ||
throws MalformedInputException; | ||
|
||
void decompress(ByteBuffer input, ByteBuffer output) | ||
throws MalformedInputException; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/io/airlift/compress/MalformedInputException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress; | ||
|
||
public class MalformedInputException | ||
extends RuntimeException | ||
{ | ||
private final long offset; | ||
|
||
public MalformedInputException(long offset) | ||
{ | ||
this(offset, "Malformed input"); | ||
} | ||
|
||
public MalformedInputException(long offset, String reason) | ||
{ | ||
super(reason + ": offset=" + offset); | ||
this.offset = offset; | ||
} | ||
|
||
public long getOffset() | ||
{ | ||
return offset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress.bzip2; | ||
|
||
public class BZip2Codec | ||
extends io.airlift.compress.v2.bzip2.BZip2Codec | ||
{ | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/io/airlift/compress/deflate/JdkDeflateCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress.deflate; | ||
|
||
public class JdkDeflateCodec | ||
extends io.airlift.compress.v2.deflate.JdkDeflateCodec | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress.gzip; | ||
|
||
public class JdkGzipCodec | ||
extends io.airlift.compress.v2.gzip.JdkGzipCodec | ||
{ | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/io/airlift/compress/hadoop/HadoopStreams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress.hadoop; | ||
|
||
public interface HadoopStreams | ||
extends io.airlift.compress.v2.hadoop.HadoopStreams | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress.lz4; | ||
|
||
public class Lz4Codec | ||
extends io.airlift.compress.v2.lz4.Lz4Codec | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress.lz4; | ||
|
||
import io.airlift.compress.Compressor; | ||
import io.airlift.compress.v2.lz4.Lz4JavaCompressor; | ||
import io.airlift.compress.v2.lz4.Lz4NativeCompressor; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.nio.ByteBuffer; | ||
|
||
import static java.lang.Math.toIntExact; | ||
|
||
public class Lz4Compressor | ||
implements Compressor | ||
{ | ||
private static final boolean NATIVE_ENABLED = Lz4NativeCompressor.isEnabled(); | ||
private final io.airlift.compress.v2.lz4.Lz4Compressor compressor; | ||
|
||
public Lz4Compressor() | ||
{ | ||
this.compressor = NATIVE_ENABLED ? new Lz4NativeCompressor() : new Lz4JavaCompressor(); | ||
} | ||
|
||
@Override | ||
public int maxCompressedLength(int uncompressedSize) | ||
{ | ||
return compressor.maxCompressedLength(uncompressedSize); | ||
} | ||
|
||
@Override | ||
public int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) | ||
{ | ||
MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); | ||
MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); | ||
|
||
return toIntExact(compressor.compress(inputSegment, outputSegment)); | ||
} | ||
|
||
@Override | ||
public void compress(ByteBuffer input, ByteBuffer output) | ||
{ | ||
MemorySegment inputSegment = MemorySegment.ofBuffer(input); | ||
MemorySegment outputSegment = MemorySegment.ofBuffer(output); | ||
|
||
int written = compressor.compress(inputSegment, outputSegment); | ||
output.position(output.position() + written); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/io/airlift/compress/lz4/Lz4Decompressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress.lz4; | ||
|
||
import io.airlift.compress.Decompressor; | ||
import io.airlift.compress.MalformedInputException; | ||
import io.airlift.compress.v2.lz4.Lz4JavaDecompressor; | ||
import io.airlift.compress.v2.lz4.Lz4NativeDecompressor; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.nio.ByteBuffer; | ||
|
||
import static java.lang.Math.toIntExact; | ||
|
||
public class Lz4Decompressor | ||
implements Decompressor | ||
{ | ||
private static final boolean NATIVE_ENABLED = Lz4NativeDecompressor.isEnabled(); | ||
private final io.airlift.compress.v2.lz4.Lz4Decompressor decompressor; | ||
|
||
public Lz4Decompressor() | ||
{ | ||
this.decompressor = NATIVE_ENABLED ? new Lz4NativeDecompressor() : new Lz4JavaDecompressor(); | ||
} | ||
|
||
@Override | ||
public int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) | ||
throws MalformedInputException | ||
{ | ||
MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); | ||
MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); | ||
|
||
return toIntExact(decompressor.decompress(inputSegment, outputSegment)); | ||
} | ||
|
||
@Override | ||
public void decompress(ByteBuffer input, ByteBuffer output) | ||
throws MalformedInputException | ||
{ | ||
MemorySegment inputSegment = MemorySegment.ofBuffer(input); | ||
MemorySegment outputSegment = MemorySegment.ofBuffer(output); | ||
|
||
int written = decompressor.decompress(inputSegment, outputSegment); | ||
output.position(output.position() + written); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/io/airlift/compress/lz4/Lz4RawCompressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress.lz4; | ||
|
||
public class Lz4RawCompressor | ||
{ | ||
private static final int HASH_LOG = 12; | ||
|
||
public static final int MAX_TABLE_SIZE = (1 << HASH_LOG); | ||
|
||
private Lz4RawCompressor() {} | ||
|
||
public static int maxCompressedLength(int sourceLength) | ||
{ | ||
return sourceLength + sourceLength / 255 + 16; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.airlift.compress.lzo; | ||
|
||
public class LzoCodec | ||
extends io.airlift.compress.v2.lzo.LzoCodec | ||
{ | ||
} |
Oops, something went wrong.