-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support zstd compression via zstd-jni.
- Loading branch information
Showing
21 changed files
with
539 additions
and
53 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
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
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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/io/github/nstdio/http/ext/spi/DelegatingCompressionFactory.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,43 @@ | ||
/* | ||
* Copyright (C) 2025 Edgar Asatryan | ||
* | ||
* 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.github.nstdio.http.ext.spi; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
class DelegatingCompressionFactory extends CompressionFactoryBase { | ||
|
||
private final CompressionFactory delegate; | ||
|
||
DelegatingCompressionFactory(CompressionFactory delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
InputStream doDecompressing(InputStream in, String type) throws IOException { | ||
if (delegate == null) { | ||
throw new IllegalStateException("No delegate available"); | ||
} | ||
|
||
return delegate.decompressing(in, type); | ||
} | ||
|
||
@Override | ||
public List<String> supported() { | ||
return delegate != null ? delegate.supported() : List.of(); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/io/github/nstdio/http/ext/spi/OptionalZstdCompressionFactory.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,26 @@ | ||
/* | ||
* Copyright (C) 2025 Edgar Asatryan | ||
* | ||
* 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.github.nstdio.http.ext.spi; | ||
|
||
import static io.github.nstdio.http.ext.spi.Classpath.isZstdJniPresent; | ||
|
||
public class OptionalZstdCompressionFactory extends DelegatingCompressionFactory { | ||
|
||
public OptionalZstdCompressionFactory() { | ||
super(isZstdJniPresent() ? new ZstdJniCompressionFactory() : null); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/io/github/nstdio/http/ext/spi/ZstdJniCompressionFactory.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 @@ | ||
/* | ||
* Copyright (C) 2025 Edgar Asatryan | ||
* | ||
* 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.github.nstdio.http.ext.spi; | ||
|
||
import com.github.luben.zstd.ZstdInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
final class ZstdJniCompressionFactory implements CompressionFactory { | ||
|
||
private final List<String> supported = List.of("zstd"); | ||
|
||
@Override | ||
public List<String> supported() { | ||
return supported; | ||
} | ||
|
||
@Override | ||
public InputStream decompressing(InputStream in, String type) throws IOException { | ||
return new ZstdInputStream(in); | ||
} | ||
} |
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
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
47 changes: 47 additions & 0 deletions
47
src/spiTest/java/io/github/nstdio/http/ext/jupiter/FilteredClassLoader.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,47 @@ | ||
/* | ||
* Copyright (C) 2025 Edgar Asatryan | ||
* | ||
* 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.github.nstdio.http.ext.jupiter; | ||
|
||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public final class FilteredClassLoader extends URLClassLoader { | ||
|
||
private final List<Class<?>> classes; | ||
|
||
public FilteredClassLoader(Class<?>... classes) { | ||
this(FilteredClassLoader.class.getClassLoader(), classes); | ||
} | ||
|
||
public FilteredClassLoader(ClassLoader parent, Class<?>... classes) { | ||
super(new URL[0], parent); | ||
this.classes = Arrays.asList(classes); | ||
} | ||
|
||
@Override | ||
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { | ||
for (var cls : classes) { | ||
if (cls.getName().equals(name)) { | ||
throw new ClassNotFoundException(); | ||
} | ||
} | ||
|
||
return super.loadClass(name, resolve); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/spiTest/java/io/github/nstdio/http/ext/jupiter/FilteredClassLoaderTest.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,44 @@ | ||
/* | ||
* Copyright (C) 2025 Edgar Asatryan | ||
* | ||
* 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.github.nstdio.http.ext.jupiter; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* {@code @FilteredClassLoaderTest} is used to filter certain classes from {@link Thread#getContextClassLoader()}. Note | ||
* that this annotation would not have effect on any other classloader that is used for loading classes, resources etc. | ||
*/ | ||
@Target({ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Test | ||
@ExtendWith(FilteredClassLoaderTestExtension.class) | ||
public @interface FilteredClassLoaderTest { | ||
|
||
/** | ||
* The list of classes that needs to hidden when executing annotated element. | ||
* | ||
* @return The list of classes. | ||
*/ | ||
Class<?>[] value() default {}; | ||
} |
Oops, something went wrong.