当前位置: 首页 > news >正文

响应式网站设计案例手机网站智能建站

响应式网站设计案例,手机网站智能建站,商派商城网站建设方案,临沂教育平台网站建设源码解析 /*** 作用是从给定的资源(如文件或输入流)中加载 .properties 文件,* 并将属性键值对转换为带有来源信息(origin)的 OriginTrackedValue 对象。*/ public class OriginTrackedPropertiesLoader {private fin…

源码解析

/*** 作用是从给定的资源(如文件或输入流)中加载 .properties 文件,* 并将属性键值对转换为带有来源信息(origin)的 OriginTrackedValue 对象。*/
public class OriginTrackedPropertiesLoader {private final Resource resource;/*** Create a new {@link OriginTrackedPropertiesLoader} instance.* @param resource the resource of the {@code .properties} data*/public OriginTrackedPropertiesLoader(Resource resource) {Assert.notNull(resource, "Resource must not be null");this.resource = resource;}/*** Load {@code .properties} data and return a map of {@code String} ->* {@link OriginTrackedValue}.* @return the loaded properties* @throws IOException on read error*/public Map<String, OriginTrackedValue> load() throws IOException {return load(true);}/*** 加载配置数据到一个Map中,根据指定的资源文件。* 如果expandLists为true,则将列表类型的配置项展开。** @param expandLists 是否展开列表类型的配置项* @return 包含配置数据的Map,键为配置项名称,值为配置项的值和来源信息* @throws IOException 如果读取资源文件时发生错误*/Map<String, OriginTrackedValue> load(boolean expandLists) throws IOException {//创建CharacterReader对象,用于逐行读取资源文件内容。try (CharacterReader reader = new CharacterReader(this.resource)) {//初始化结果MapMap<String, OriginTrackedValue> result = new LinkedHashMap<>();//初始化字符串缓冲区StringBuilder buffer = new StringBuilder();//循环读取逐行资源文件内容,直到文件末尾while (reader.read()) {//读取配置项的键名,并去除前后空格String key = loadKey(buffer, reader).trim();//如果配置项是列表类型且需要展开列表,则处理列表配置项if (expandLists && key.endsWith("[]")) {//去除列表配置项的"[]"后缀key = key.substring(0, key.length() - 2);//初始化列表索引int index = 0;//循环读取列表中的每个配置项do {//读取配置项的值OriginTrackedValue value = loadValue(buffer, reader, true);//将配置项添加到结果Map中,键名格式为key[index]put(result, key + "[" + (index++) + "]", value);//如果当前行不是行尾,则继续读取if (!reader.isEndOfLine()) {reader.read();}} while (!reader.isEndOfLine());}else {//读取非列表配置项的值OriginTrackedValue value = loadValue(buffer, reader, false);//将配置项添加到结果Map中put(result, key, value);}}//返回包含所有配置项的Mapreturn result;}}/*** 从输入中加载属性键* 该方法负责读取输入直到遇到属性分隔符或行尾,同时忽略前导和尾随的空白字符** @param buffer 用于存储读取的键的字符串构建器* @param reader 提供输入字符的字符阅读器* @return 返回读取的属性键的字符串表示* @throws IOException 如果读取过程中发生I/O错误*/private String loadKey(StringBuilder buffer, CharacterReader reader) throws IOException {// 清空缓冲区以准备读取新的键buffer.setLength(0);// 初始化前一个字符是否为空白字符的标志boolean previousWhitespace = false;// 循环读取直到行尾while (!reader.isEndOfLine()) {// 如果遇到属性分隔符,读取下一个字符并返回当前缓冲区的内容if (reader.isPropertyDelimiter()) {reader.read();return buffer.toString();}// 如果当前字符不是空白字符,但前一个字符是空白字符,则返回当前缓冲区的内容if (!reader.isWhiteSpace() && previousWhitespace) {return buffer.toString();}// 更新前一个字符是否为空白字符的标志previousWhitespace = reader.isWhiteSpace();// 将当前字符追加到缓冲区中buffer.append(reader.getCharacter());// 读取下一个字符reader.read();}// 如果到达行尾,返回当前缓冲区的内容return buffer.toString();}/*** 从输入中加载一行值,可以选择性地在列表分隔符处分割** @param buffer 缓存区,用于存储从输入中读取的值* @param reader 字符读取器,用于从输入源读取字符* @param splitLists 指示是否应在遇到列表分隔符时分割的布尔值* @return 返回一个包含值及其来源信息的OriginTrackedValue对象* @throws IOException 如果在读取过程中发生I/O错误*/private OriginTrackedValue loadValue(StringBuilder buffer, CharacterReader reader, boolean splitLists)throws IOException {// 清空缓冲区以准备读取新的值buffer.setLength(0);// 跳过行首的空白字符,直到遇到非空白字符或行尾while (reader.isWhiteSpace() && !reader.isEndOfLine()) {reader.read();}// 记录当前读取位置,用于后续创建Origin对象Location location = reader.getLocation();// 读取字符直到行尾或(如果splitLists为真)遇到列表分隔符while (!reader.isEndOfLine() && !(splitLists && reader.isListDelimiter())) {buffer.append(reader.getCharacter());reader.read();}// 创建一个表示值来源的Origin对象Origin origin = new TextResourceOrigin(this.resource, location);// 使用缓冲区中的字符串和其来源信息创建并返回一个OriginTrackedValue对象return OriginTrackedValue.of(buffer.toString(), origin);}/*** Reads characters from the source resource, taking care of skipping comments,* handling multi-line values and tracking {@code '\'} escapes.* 用于逐字符读取文件内容,处理注释、转义字符、多行值等特殊情况。* 提供了多种辅助方法来跳过空白字符、处理注释、读取转义字符等。*/private static class CharacterReader implements Closeable{//省略......}}

案例

test-properties.properties配置文件

   # foo
blah   =   hello world
bar   foo=baz
hello   world
proper\\ty=test
foo
bat = a\\
bling = a=b#commented-property=test
test=properties
test-unicode=properties\u0026test# comment ending \
test\=property=helloworld
test-colon-separator: my-property
test-tab-property=foo\tbar
test-return-property=foo\rbar
test-newline-property=foo\nbar
test-form-feed-property=foo\fbar
test-whitespace-property   =   foo   bar
test-multiline= a\b\\\c
foods[]=Apple,\
Orange,\
Strawberry,\
Mango
languages[perl]=Elite
languages[python]=Elite
language[pascal]=Lame
test-multiline-immediate=\
foo
!commented-two=bang\
test-bang-property=foo!
another=bar
test-property-value-comment=foo \
!bar #foo
test-multiline-immediate-bang=\
!foo#test ISO 8859-1
test-iso8859-1-chars=����������test-with-trailing-space= trailing 
	private ClassPathResource resource;private Map<String, OriginTrackedValue> properties;@Testvoid compareToJavaProperties() throws Exception {String path = "test-properties.properties";this.resource = new ClassPathResource(path, getClass());this.properties = new OriginTrackedPropertiesLoader(this.resource).load();Properties java = PropertiesLoaderUtils.loadProperties(this.resource);Properties ours = new Properties();new OriginTrackedPropertiesLoader(this.resource).load(false).forEach((k, v) -> System.out.println(k+":"+v.getValue()));}

运行结果

blah:hello world
bar:foo=baz
hello:world
proper\ty:test
foo:
bat:a\
bling:a=b
test:properties
test-unicode:properties&test
test=property:helloworld
test-colon-separator:my-property
test-tab-property:foo	bar
bar
test-newline-property:foo
bar
test-form-feed-property:foobar
test-whitespace-property:foo   bar
test-multiline:ab\c
foods[]:Apple,Orange,Strawberry,Mango
languages[perl]:Elite
languages[python]:Elite
language[pascal]:Lame
test-multiline-immediate:foo
test-bang-property:foo!
another:bar
test-property-value-comment:foo !bar #foo
test-multiline-immediate-bang:!foo
test-iso8859-1-chars:����������
test-with-trailing-space:trailing 
http://www.yayakq.cn/news/690108/

相关文章:

  • 做网站的边框素材新年祝福语在线制作网站
  • 建网站的资料成都网站设计培训班
  • 做网站被黑后怎么办广州做网站信科建设
  • 公众号做电影网站赚钱石家庄官网制作
  • 小学门户网站建设建立网站的链接结构有哪几种形式简述其各自的优缺点
  • 景安网站备案表格网页 网站 站点的区别
  • 如何用微信做网站wordpress is home
  • 天津做网站哪家比较好ui平面设计是做什么的
  • 自助健站钢筋网片厂家电话
  • 常州做网站哪家好怎么制作网站论坛模板
  • 网站权重多少比较好门户网站做免费相亲的
  • 个人网站是商业的吗证件照片制作软件免费下载
  • 广东省建设执业资格注册中心官方网站网站推广营销的步骤
  • 网站建设公司圣辉友联模具培训网站建设
  • 网页怎么搜索关键词嘉兴seo计费管理
  • 网站首页原型图咋做网站建设基础筹备
  • js做网站登录界面和韩国做贸易的网站
  • ps设计网页临沂网站优化哪家好
  • 郑州网站建设+论坛用营销的方式介绍自己
  • 免费单页网站在线制作有没有做任务拿佣金的网站
  • 专业做英文网站南昌网站设计企业
  • 四川住房与城乡建设部网站东莞网络推广公司排行榜
  • flashxml网站模板济南企业网站制
  • thinkphp 网站模版性价比最高的网站建设
  • 韩国做网站网站违法不一个好的网站怎样布局
  • 17网站一起做网店普宁池尾俄罗斯乌克兰地图
  • 灯网一家专门做灯的网站关键词优化好
  • 网站设计方案策划宁波创建网站
  • 设计 微网站建筑工程网络图实例
  • 怎样做旅游摄影网站友情链接发布