Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
430c4c4e
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看板
提交
430c4c4e
编写于
2月 17, 2011
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6526860: (fc) FileChannel.position returns 0 when FileOutputStream opened in append mode
Reviewed-by: forax
上级
e22c5084
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
47 addition
and
35 deletion
+47
-35
src/share/classes/sun/nio/ch/FileChannelImpl.java
src/share/classes/sun/nio/ch/FileChannelImpl.java
+4
-1
src/solaris/classes/sun/nio/fs/UnixChannelFactory.java
src/solaris/classes/sun/nio/fs/UnixChannelFactory.java
+1
-1
test/java/nio/channels/FileChannel/Position.java
test/java/nio/channels/FileChannel/Position.java
+42
-33
未找到文件。
src/share/classes/sun/nio/ch/FileChannelImpl.java
浏览文件 @
430c4c4e
...
...
@@ -51,6 +51,7 @@ public class FileChannelImpl
// File access mode (immutable)
private
final
boolean
writable
;
private
final
boolean
readable
;
private
final
boolean
append
;
// Required to prevent finalization of creating stream (immutable)
private
final
Object
parent
;
...
...
@@ -67,6 +68,7 @@ public class FileChannelImpl
this
.
fd
=
fd
;
this
.
readable
=
readable
;
this
.
writable
=
writable
;
this
.
append
=
append
;
this
.
parent
=
parent
;
this
.
nd
=
new
FileDispatcherImpl
(
append
);
}
...
...
@@ -242,7 +244,8 @@ public class FileChannelImpl
if
(!
isOpen
())
return
0
;
do
{
p
=
position0
(
fd
,
-
1
);
// in append-mode then position is advanced to end before writing
p
=
(
append
)
?
nd
.
size
(
fd
)
:
position0
(
fd
,
-
1
);
}
while
((
p
==
IOStatus
.
INTERRUPTED
)
&&
isOpen
());
return
IOStatus
.
normalize
(
p
);
}
finally
{
...
...
src/solaris/classes/sun/nio/fs/UnixChannelFactory.java
浏览文件 @
430c4c4e
...
...
@@ -136,7 +136,7 @@ class UnixChannelFactory {
throw
new
IllegalArgumentException
(
"APPEND + TRUNCATE_EXISTING not allowed"
);
FileDescriptor
fdObj
=
open
(
dfd
,
path
,
pathForPermissionCheck
,
flags
,
mode
);
return
FileChannelImpl
.
open
(
fdObj
,
flags
.
read
,
flags
.
write
,
null
);
return
FileChannelImpl
.
open
(
fdObj
,
flags
.
read
,
flags
.
write
,
flags
.
append
,
null
);
}
/**
...
...
test/java/nio/channels/FileChannel/Position.java
浏览文件 @
430c4c4e
...
...
@@ -22,13 +22,16 @@
*/
/* @test
* @bug 4429043 6526860
* @summary Test position method of FileChannel
*/
import
java.io.*
;
import
java.nio.MappedByteBuffer
;
import
java.nio.channels.*
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.nio.file.*
;
import
static
java
.
nio
.
file
.
StandardOpenOption
.*;
import
java.nio.charset.Charset
;
import
java.util.Random
;
...
...
@@ -38,32 +41,42 @@ import java.util.Random;
public
class
Position
{
private
static
PrintStream
err
=
System
.
err
;
private
static
final
Charset
ISO8859_1
=
Charset
.
forName
(
"8859_1"
)
;
private
static
Random
generator
=
new
Random
();
private
static
int
CHARS_PER_LINE
=
File
.
separatorChar
==
'/'
?
5
:
6
;
private
static
File
blah
;
private
static
final
Random
generator
=
new
Random
();
public
static
void
main
(
String
[]
args
)
throws
Exception
{
blah
=
File
.
createTempFile
(
"blah"
,
null
);
blah
.
deleteOnExit
();
Path
blah
=
Files
.
createTempFile
(
"blah"
,
null
);
blah
.
toFile
().
deleteOnExit
();
initTestFile
(
blah
);
FileInputStream
fis
=
new
FileInputStream
(
blah
);
FileChannel
c
=
fis
.
getChannel
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
try
(
FileChannel
fc
=
(
generator
.
nextBoolean
())
?
FileChannel
.
open
(
blah
,
READ
)
:
new
FileInputStream
(
blah
.
toFile
()).
getChannel
())
{
for
(
int
j
=
0
;
j
<
100
;
j
++)
{
long
newPos
=
generator
.
nextInt
(
1000
);
fc
.
position
(
newPos
);
if
(
fc
.
position
()
!=
newPos
)
throw
new
RuntimeException
(
"Position failed"
);
}
}
}
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
long
newPos
=
generator
.
nextInt
(
1000
);
c
.
position
(
newPos
);
if
(
c
.
position
()
!=
newPos
)
throw
new
RuntimeException
(
"Position failed"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
try
(
FileChannel
fc
=
(
generator
.
nextBoolean
())
?
FileChannel
.
open
(
blah
,
APPEND
)
:
new
FileOutputStream
(
blah
.
toFile
(),
true
).
getChannel
())
{
for
(
int
j
=
0
;
j
<
10
;
j
++)
{
if
(
fc
.
position
()
!=
fc
.
size
())
throw
new
RuntimeException
(
"Position expected to be size"
);
byte
[]
buf
=
new
byte
[
generator
.
nextInt
(
100
)];
fc
.
write
(
ByteBuffer
.
wrap
(
buf
));
}
}
}
c
.
close
();
fis
.
close
();
blah
.
delete
();
Files
.
delete
(
blah
);
}
/**
...
...
@@ -78,19 +91,15 @@ public class Position {
* 3999
*
*/
private
static
void
initTestFile
(
File
blah
)
throws
Exception
{
FileOutputStream
fos
=
new
FileOutputStream
(
blah
);
BufferedWriter
awriter
=
new
BufferedWriter
(
new
OutputStreamWriter
(
fos
,
"8859_1"
));
for
(
int
i
=
0
;
i
<
4000
;
i
++)
{
String
number
=
new
Integer
(
i
).
toString
();
for
(
int
h
=
0
;
h
<
4
-
number
.
length
();
h
++)
awriter
.
write
(
"0"
);
awriter
.
write
(
""
+
i
);
awriter
.
newLine
();
private
static
void
initTestFile
(
Path
blah
)
throws
IOException
{
try
(
BufferedWriter
awriter
=
Files
.
newBufferedWriter
(
blah
,
ISO8859_1
))
{
for
(
int
i
=
0
;
i
<
4000
;
i
++)
{
String
number
=
new
Integer
(
i
).
toString
();
for
(
int
h
=
0
;
h
<
4
-
number
.
length
();
h
++)
awriter
.
write
(
"0"
);
awriter
.
write
(
""
+
i
);
awriter
.
newLine
();
}
}
awriter
.
flush
();
awriter
.
close
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录