Skip to content

Commit

Permalink
Refactor HttpContentCompressorSubstitutions for consistency
Browse files Browse the repository at this point in the history
Adopt `Target_*` naming convention for substitution classes
  • Loading branch information
zakkak committed Oct 4, 2024
1 parent 6467ad9 commit 41728ea
Showing 1 changed file with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,61 @@
import io.netty.channel.ChannelHandlerContext;

public class HttpContentCompressorSubstitutions {
}

@TargetClass(className = "io.netty.handler.codec.compression.ZstdEncoder", onlyWith = IsZstdAbsent.class)
public static final class ZstdEncoderFactorySubstitution {

@Substitute
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception {
throw new UnsupportedOperationException();
}
@TargetClass(className = "io.netty.handler.codec.compression.ZstdEncoder", onlyWith = IsZstdAbsent.class)
final class Target_io_netty_handler_codec_compression_ZstdEncoder {

@Substitute
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) {
throw new UnsupportedOperationException();
}
@Substitute
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception {
throw new UnsupportedOperationException();
}

@Substitute
public void flush(final ChannelHandlerContext ctx) {
throw new UnsupportedOperationException();
}
@Substitute
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) {
throw new UnsupportedOperationException();
}

@Substitute
@TargetClass(className = "io.netty.handler.codec.compression.ZstdConstants", onlyWith = IsZstdAbsent.class)
public static final class ZstdConstants {
public void flush(final ChannelHandlerContext ctx) {
throw new UnsupportedOperationException();
}
}

// The constants make <clinit> calls to com.github.luben.zstd.Zstd so we cut links with that substitution.
@Substitute
@TargetClass(className = "io.netty.handler.codec.compression.ZstdConstants", onlyWith = IsZstdAbsent.class)
final class Target_io_netty_handler_codec_compression_ZstdConstants {

static final int DEFAULT_COMPRESSION_LEVEL = 0;
// The constants make <clinit> calls to com.github.luben.zstd.Zstd so we cut links with that substitution.

static final int MIN_COMPRESSION_LEVEL = 0;
static final int DEFAULT_COMPRESSION_LEVEL = 0;

static final int MAX_COMPRESSION_LEVEL = 0;
static final int MIN_COMPRESSION_LEVEL = 0;

static final int MAX_BLOCK_SIZE = 0;
static final int MAX_COMPRESSION_LEVEL = 0;

static final int DEFAULT_BLOCK_SIZE = 0;
}
static final int MAX_BLOCK_SIZE = 0;

public static class IsZstdAbsent implements BooleanSupplier {
static final int DEFAULT_BLOCK_SIZE = 0;
}

private boolean zstdAbsent;
class IsZstdAbsent implements BooleanSupplier {

public IsZstdAbsent() {
try {
Class.forName("com.github.luben.zstd.Zstd");
zstdAbsent = false;
} catch (Exception e) {
// It can be a classloading issue (the library is not available), or a native issue
// (the library for the current OS/arch is not available)
zstdAbsent = true;
}
}
private boolean zstdAbsent;

@Override
public boolean getAsBoolean() {
return zstdAbsent;
public IsZstdAbsent() {
try {
Class.forName("com.github.luben.zstd.Zstd");
zstdAbsent = false;
} catch (Exception e) {
// It can be a classloading issue (the library is not available), or a native issue
// (the library for the current OS/arch is not available)
zstdAbsent = true;
}
}

@Override
public boolean getAsBoolean() {
return zstdAbsent;
}
}

0 comments on commit 41728ea

Please sign in to comment.