diff options
author | jfrijters <jfrijters> | 2011-08-19 13:24:19 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2011-08-19 13:24:19 +0400 |
commit | 4f49b8f6792a37b1c005a0e9b5fcc1879aa57d90 (patch) | |
tree | fd9853e54e94a7e703dcc83a6d1da358c2cce3e8 /openjdk/sun/nio/ch/FileDispatcherImpl.java | |
parent | 883965d3543fe43ab960a7010188cd940e0bce9f (diff) |
Fixed several append issues:
- FileChannelImpl.truncate() should not attempt to seek (would throw an exception)
- FileDispatcherImpl.write() doesn't need to seek to EOF
- FileDispatcherImpl.truncate() can't use fd.setLength() to truncate on append FileStream, so we open the file again to truncate it
- NetFileSystemProvider.newFileChannel() should not set FileSystemRights.Write in append mode
Diffstat (limited to 'openjdk/sun/nio/ch/FileDispatcherImpl.java')
-rw-r--r-- | openjdk/sun/nio/ch/FileDispatcherImpl.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/openjdk/sun/nio/ch/FileDispatcherImpl.java b/openjdk/sun/nio/ch/FileDispatcherImpl.java index e8d4a55b..9d836dfd 100644 --- a/openjdk/sun/nio/ch/FileDispatcherImpl.java +++ b/openjdk/sun/nio/ch/FileDispatcherImpl.java @@ -56,9 +56,6 @@ class FileDispatcherImpl extends FileDispatcher } int write(FileDescriptor fd, byte[] buf, int offset, int length) throws IOException { - if (append) { - fd.seek(fd.length()); - } fd.writeBytes(buf, offset, length); return length; } @@ -129,7 +126,14 @@ class FileDispatcherImpl extends FileDispatcher } int truncate(FileDescriptor fd, long size) throws IOException { - fd.setLength(size); + if (append) { + // HACK in append mode we're not allowed to truncate, so we try to reopen the file and truncate that + try (FileOutputStream fos = new FileOutputStream(((FileStream)fd.getStream()).get_Name())) { + fos.getFD().setLength(size); + } + } else { + fd.setLength(size); + } return 0; } |