Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
abdd16ff
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
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看板
提交
abdd16ff
编写于
8月 23, 2010
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
Reviewed-by: forax, chegar
上级
eca350c8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
23 deletion
+58
-23
src/share/classes/sun/nio/ch/FileChannelImpl.java
src/share/classes/sun/nio/ch/FileChannelImpl.java
+58
-23
未找到文件。
src/share/classes/sun/nio/ch/FileChannelImpl.java
浏览文件 @
abdd16ff
...
...
@@ -429,24 +429,45 @@ public class FileChannelImpl
}
}
private
long
transferToTrustedChannel
(
long
position
,
int
icount
,
// Maximum size to map when using a mapped buffer
private
static
final
long
MAPPED_TRANSFER_SIZE
=
8L
*
1024L
*
1024L
;
private
long
transferToTrustedChannel
(
long
position
,
long
count
,
WritableByteChannel
target
)
throws
IOException
{
if
(
!((
target
instanceof
FileChannelImpl
)
||
(
target
instanceof
SelChImpl
)
))
boolean
isSelChImpl
=
(
target
instanceof
SelChImpl
);
if
(!((
target
instanceof
FileChannelImpl
)
||
isSelChImpl
))
return
IOStatus
.
UNSUPPORTED
;
// Trusted target: Use a mapped buffer
MappedByteBuffer
dbb
=
null
;
try
{
dbb
=
map
(
MapMode
.
READ_ONLY
,
position
,
icount
);
// ## Bug: Closing this channel will not terminate the write
return
target
.
write
(
dbb
);
}
finally
{
if
(
dbb
!=
null
)
unmap
(
dbb
);
long
remaining
=
count
;
while
(
remaining
>
0L
)
{
long
size
=
Math
.
min
(
remaining
,
MAPPED_TRANSFER_SIZE
);
try
{
MappedByteBuffer
dbb
=
map
(
MapMode
.
READ_ONLY
,
position
,
size
);
try
{
// ## Bug: Closing this channel will not terminate the write
int
n
=
target
.
write
(
dbb
);
assert
n
>=
0
;
remaining
-=
n
;
if
(
isSelChImpl
)
{
// one attempt to write to selectable channel
break
;
}
assert
n
>
0
;
position
+=
n
;
}
finally
{
unmap
(
dbb
);
}
}
catch
(
IOException
ioe
)
{
// Only throw exception if no bytes have been written
if
(
remaining
==
count
)
throw
ioe
;
break
;
}
}
return
count
-
remaining
;
}
private
long
transferToArbitraryChannel
(
long
position
,
int
icount
,
...
...
@@ -524,20 +545,34 @@ public class FileChannelImpl
long
position
,
long
count
)
throws
IOException
{
// Note we could loop here to accumulate more at once
synchronized
(
src
.
positionLock
)
{
long
p
=
src
.
position
();
int
icount
=
(
int
)
Math
.
min
(
Math
.
min
(
count
,
Integer
.
MAX_VALUE
),
src
.
size
()
-
p
);
// ## Bug: Closing this channel will not terminate the write
MappedByteBuffer
bb
=
src
.
map
(
MapMode
.
READ_ONLY
,
p
,
icount
);
try
{
long
n
=
write
(
bb
,
position
);
src
.
position
(
p
+
n
);
return
n
;
}
finally
{
unmap
(
bb
);
long
pos
=
src
.
position
();
long
max
=
Math
.
min
(
count
,
src
.
size
()
-
pos
);
long
remaining
=
max
;
long
p
=
pos
;
while
(
remaining
>
0L
)
{
long
size
=
Math
.
min
(
remaining
,
MAPPED_TRANSFER_SIZE
);
// ## Bug: Closing this channel will not terminate the write
MappedByteBuffer
bb
=
src
.
map
(
MapMode
.
READ_ONLY
,
p
,
size
);
try
{
long
n
=
write
(
bb
,
position
);
assert
n
>
0
;
p
+=
n
;
position
+=
n
;
remaining
-=
n
;
}
catch
(
IOException
ioe
)
{
// Only throw exception if no bytes have been written
if
(
remaining
==
max
)
throw
ioe
;
break
;
}
finally
{
unmap
(
bb
);
}
}
long
nwritten
=
max
-
remaining
;
src
.
position
(
pos
+
nwritten
);
return
nwritten
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录