Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzh_me
Sureness
提交
901663ec
Sureness
项目概览
lzh_me
/
Sureness
与 Fork 源项目一致
Fork自
sureness / Sureness
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Sureness
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
901663ec
编写于
4月 23, 2020
作者:
sinat_25235033
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use cache when loading resource from document
上级
7eadc1bf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
26 deletion
+23
-26
core/src/main/java/com/usthe/sureness/provider/ducument/DocumentResourceAccess.java
...he/sureness/provider/ducument/DocumentResourceAccess.java
+16
-24
core/src/main/java/com/usthe/sureness/provider/ducument/DocumentResourceDefaultProvider.java
...ss/provider/ducument/DocumentResourceDefaultProvider.java
+7
-2
未找到文件。
core/src/main/java/com/usthe/sureness/provider/ducument/DocumentResourceAccess.java
浏览文件 @
901663ec
...
...
@@ -2,14 +2,11 @@ package com.usthe.sureness.provider.ducument;
import
org.yaml.snakeyaml.Yaml
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStreamWriter
;
import
java.io.Writer
;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
/**
* 资源文件里内容的操作类
...
...
@@ -35,6 +32,16 @@ public class DocumentResourceAccess {
public
static
DocumentResourceEntity
loadConfig
()
throws
IOException
{
Yaml
yaml
=
new
Yaml
();
InputStream
inputStream
=
DocumentResourceAccess
.
class
.
getClassLoader
().
getResourceAsStream
(
yamlFileName
);
if
(
inputStream
==
null
)
{
File
yamlFile
=
new
File
(
yamlFileName
);
if
(
yamlFile
.
exists
())
{
try
(
FileInputStream
fileInputStream
=
new
FileInputStream
(
yamlFile
))
{
return
yaml
.
loadAs
(
fileInputStream
,
DocumentResourceEntity
.
class
);
}
catch
(
IOException
e
)
{
throw
new
IOException
(
e
);
}
}
}
if
(
inputStream
==
null
)
{
throw
new
FileNotFoundException
(
"sureness file: "
+
DEFAULT_FILE_NAME
+
" not found, "
+
"please create the file if you need config resource"
);
...
...
@@ -43,25 +50,10 @@ public class DocumentResourceAccess {
}
/**
* 将更新的信息写入到配置文件中
* @param entity 写入的内容实体
* @throws IOException 文件不存在或者读写异常时
* config file path name
* @param fileName 文件路径名称
*/
public
static
void
dumpConfig
(
DocumentResourceEntity
entity
)
throws
IOException
{
Yaml
yaml
=
new
Yaml
();
URL
url
=
DocumentResourceAccess
.
class
.
getClassLoader
().
getResource
(
yamlFileName
);
if
(
url
==
null
)
{
throw
new
FileNotFoundException
(
"sureness file: "
+
DEFAULT_FILE_NAME
+
" not found, "
+
"please create the file if you need config resource"
);
}
try
(
Writer
writer
=
new
OutputStreamWriter
(
new
FileOutputStream
(
url
.
getPath
()),
StandardCharsets
.
UTF_8
))
{
yaml
.
dump
(
entity
,
writer
);
}
catch
(
IOException
e
)
{
throw
new
IOException
(
e
);
}
}
public
static
void
setYamlName
(
String
name
)
{
yamlFileName
=
name
;
public
static
void
setYamlName
(
String
fileName
)
{
yamlFileName
=
fileName
;
}
}
core/src/main/java/com/usthe/sureness/provider/ducument/DocumentResourceDefaultProvider.java
浏览文件 @
901663ec
...
...
@@ -16,6 +16,7 @@ import java.util.Optional;
import
java.util.Set
;
/**
* provide resource and account data loading from yaml document
* @author tomsun28
* @date 22:40 2019-05-24
*/
...
...
@@ -36,7 +37,9 @@ public class DocumentResourceDefaultProvider implements PathTreeProvider, Surene
@Override
public
Set
<
String
>
providePathData
()
{
try
{
DocumentResourceEntity
entity
=
DocumentResourceAccess
.
loadConfig
();
if
(
entity
==
null
)
{
entity
=
DocumentResourceAccess
.
loadConfig
();
}
List
<
String
>
resource
=
entity
.
getResourceRole
();
if
(
resource
!=
null
)
{
return
new
HashSet
<>(
entity
.
getResourceRole
());
...
...
@@ -51,7 +54,9 @@ public class DocumentResourceDefaultProvider implements PathTreeProvider, Surene
@Override
public
Set
<
String
>
provideExcludedResource
()
{
try
{
DocumentResourceEntity
entity
=
DocumentResourceAccess
.
loadConfig
();
if
(
entity
==
null
)
{
entity
=
DocumentResourceAccess
.
loadConfig
();
}
List
<
String
>
resource
=
entity
.
getExcludedResource
();
if
(
resource
!=
null
)
{
return
new
HashSet
<>(
resource
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录