chore[class]: adjust code

This commit is contained in:
sun
2023-09-06 11:34:15 +08:00
parent f7b06a086e
commit f14488cdc8
2 changed files with 13 additions and 1 deletions
@@ -16,12 +16,15 @@ import com.zfoo.protocol.anno.Protocol;
import com.zfoo.protocol.xml.XmlModuleDefinition;
import com.zfoo.protocol.xml.XmlProtocolDefinition;
import com.zfoo.protocol.xml.XmlProtocols;
import io.netty.buffer.AbstractByteBufAllocator;
import io.netty.buffer.AbstractReferenceCountedByteBuf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import java.util.HashSet;
import java.util.List;
/**
* Register runtime hints for the token library
@@ -45,5 +48,12 @@ public class GraalvmProtocolHints implements RuntimeHintsRegistrar {
classes.addAll(filterClasses);
HintUtils.registerRelevantClasses(hints, classes);
// netty
HintUtils.registerClasses(hints, List.of(AbstractByteBufAllocator.class, AbstractReferenceCountedByteBuf.class));
var include = "*.protocol";
hints.resources().registerPattern(include);
logger.info("Protocol graalvm aot hints register resources [{}]", include);
}
}
@@ -317,7 +317,9 @@ public abstract class ClassUtils {
* @param filePath 一般指resources中的文件,也可以在jar中
*/
public static InputStream getFileFromClassPath(String filePath) throws IOException {
return getDefaultClassLoader().getResource(filePath).openStream();
var classLoader = getDefaultClassLoader();
var resource = classLoader.getResource(filePath);
return resource.openStream();
}
public static String getFileFromClassPathToString(String filePath) {