package com.qianwen.core.tool.yml; import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.stream.Stream; import com.qianwen.core.tool.utils.StringUtil; import org.springframework.boot.env.OriginTrackedMapPropertySource; import org.springframework.boot.env.YamlPropertySourceLoader; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.DefaultPropertySourceFactory; import org.springframework.core.io.support.EncodedResource; import org.springframework.lang.Nullable; /* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/yml/YmlPropertyLoaderFactory.class */ public class YmlPropertyLoaderFactory extends DefaultPropertySourceFactory { public PropertySource createPropertySource(@Nullable String name, EncodedResource encodedResource) throws IOException { if (encodedResource == null) { return emptyPropertySource(name); } Resource resource = encodedResource.getResource(); String fileName = resource.getFilename(); List> sources = new YamlPropertySourceLoader().load(fileName, resource); if (sources.isEmpty()) { return emptyPropertySource(fileName); } Map ymlDataMap = new HashMap<>(32); /* Iterator> it = sources.iterator(); while (it.hasNext()) { ymlDataMap.putAll((Map) ((MapPropertySource) it.next()).getSource()); }*/ for (PropertySource source : sources) { ymlDataMap.putAll((Map)((MapPropertySource)source).getSource()); } return new OriginTrackedMapPropertySource(getSourceName(fileName, name), ymlDataMap); } private static PropertySource emptyPropertySource(@Nullable String name) { return new MapPropertySource(getSourceName(name), Collections.emptyMap()); } private static String getSourceName(String... names) { return Stream.of(names) .filter(StringUtil::isNotBlank) .findFirst() .orElse("BladeYmlPropertySource"); } }