Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
953dcdab
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
953dcdab
编写于
10月 30, 2009
作者:
W
weijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6894534: SeedGenerator shouldn't require java.nio.file to be present
Reviewed-by: alanb
上级
6b1b12bc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
98 addition
and
14 deletion
+98
-14
src/share/classes/sun/security/provider/SeedGenerator.java
src/share/classes/sun/security/provider/SeedGenerator.java
+98
-14
未找到文件。
src/share/classes/sun/security/provider/SeedGenerator.java
浏览文件 @
953dcdab
...
...
@@ -63,13 +63,13 @@ package sun.security.provider;
* @author Gadi Guy
*/
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.security.*
;
import
java.io.*
;
import
java.util.Properties
;
import
java.util.Enumeration
;
import
java.net.*
;
import
java.nio.file.DirectoryStream
;
import
java.nio.file.Path
;
import
java.util.Random
;
import
sun.security.util.Debug
;
...
...
@@ -183,26 +183,38 @@ abstract class SeedGenerator {
// The temporary dir
File
f
=
new
File
(
p
.
getProperty
(
"java.io.tmpdir"
));
int
count
=
0
;
DirectoryStream
<
Path
>
ds
=
f
.
toPath
().
newDirectoryStream
();
try
{
// Go thru files in the tmp dir using NIO's
// DirectoryStream. Fallback to File.list()
// if NIO is not available.
if
(
NIODirectoryStream
.
isAvailable
())
{
int
count
=
0
;
Iterable
<?>
stream
=
NIODirectoryStream
.
newDirectoryStream
(
f
);
// We use a Random object to choose what file names
// should be used. Otherwise on a machine with too
// many files, the same first 1024 files always get
// used. Any, We make sure the first 512 files are
// always used.
Random
r
=
new
Random
();
for
(
Path
path:
ds
)
{
if
(
count
<
512
||
r
.
nextBoolean
())
{
md
.
update
(
path
.
getName
().
toString
().
getBytes
());
}
if
(
count
++
>
1024
)
{
break
;
try
{
for
(
Object
entry:
stream
)
{
if
(
count
<
512
||
r
.
nextBoolean
())
{
md
.
update
(
NIODirectoryStream
.
getName
(
entry
).
getBytes
());
}
if
(
count
++
>
1024
)
{
break
;
}
}
}
finally
{
((
Closeable
)
stream
).
close
();
}
}
else
{
String
[]
sa
=
f
.
list
();
for
(
int
i
=
0
;
i
<
sa
.
length
;
i
++)
{
md
.
update
(
sa
[
i
].
getBytes
());
}
}
finally
{
ds
.
close
();
}
}
catch
(
Exception
ex
)
{
md
.
update
((
byte
)
ex
.
hashCode
());
...
...
@@ -505,4 +517,76 @@ abstract class SeedGenerator {
}
/**
* A wrapper of NIO DirectoryStream using reflection.
*/
private
static
class
NIODirectoryStream
{
private
static
final
Class
<?>
pathClass
=
getClass
(
"java.nio.file.Path"
);
private
static
final
Method
toPathMethod
=
(
pathClass
==
null
)
?
null
:
getMethod
(
File
.
class
,
"toPath"
);
private
static
final
Method
getNameMethod
=
getMethod
(
pathClass
,
"getName"
);
private
static
final
Method
newDirectoryStreamMethod
=
getMethod
(
pathClass
,
"newDirectoryStream"
);
private
static
Class
<?>
getClass
(
String
name
)
{
try
{
return
Class
.
forName
(
name
,
true
,
null
);
}
catch
(
ClassNotFoundException
e
)
{
return
null
;
}
}
private
static
Method
getMethod
(
Class
<?>
clazz
,
String
name
,
Class
<?>...
paramTypes
)
{
if
(
clazz
!=
null
)
{
try
{
return
clazz
.
getMethod
(
name
,
paramTypes
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
AssertionError
(
e
);
}
}
else
{
return
null
;
}
}
static
boolean
isAvailable
()
{
return
pathClass
!=
null
;
}
static
Iterable
<?>
newDirectoryStream
(
File
dir
)
throws
IOException
{
assert
pathClass
!=
null
;
try
{
Object
path
=
toPathMethod
.
invoke
(
dir
);
return
(
Iterable
<?>)
newDirectoryStreamMethod
.
invoke
(
path
);
}
catch
(
InvocationTargetException
e
)
{
Throwable
cause
=
e
.
getCause
();
if
(
cause
instanceof
IOException
)
throw
(
IOException
)
cause
;
if
(
cause
instanceof
RuntimeException
)
throw
(
RuntimeException
)
cause
;
if
(
cause
instanceof
Error
)
throw
(
Error
)
cause
;
throw
new
AssertionError
(
e
);
}
catch
(
IllegalAccessException
iae
)
{
throw
new
AssertionError
(
iae
);
}
}
static
String
getName
(
Object
path
)
{
assert
pathClass
!=
null
;
try
{
Object
name
=
getNameMethod
.
invoke
(
path
);
return
name
.
toString
();
}
catch
(
InvocationTargetException
e
)
{
throw
new
AssertionError
(
e
);
}
catch
(
IllegalAccessException
iae
)
{
throw
new
AssertionError
(
iae
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录