提交 c1d8c8a8 编写于 作者: A alanb

6984545: (fc) transferFrom does not throw NonReadableChannelException when...

6984545: (fc) transferFrom does not throw NonReadableChannelException when target is size 0 and non-readable
Reviewed-by: forax
上级 f5d5e8c9
......@@ -545,6 +545,8 @@ public class FileChannelImpl
long position, long count)
throws IOException
{
if (!src.readable)
throw new NonReadableChannelException();
synchronized (src.positionLock) {
long pos = src.position();
long max = Math.min(count, src.size() - pos);
......
......@@ -23,6 +23,7 @@
/* @test
* @bug 4434723 4482726 4559072 4638365 4795550 5081340 5103988 6253145
* 6984545
* @summary Test FileChannel.transferFrom and transferTo
* @library ..
*/
......@@ -55,6 +56,7 @@ public class Transfer {
xferTest06(); // for bug 5081340
xferTest07(); // for bug 5103988
xferTest08(); // for bug 6253145
xferTest09(); // for bug 6984545
}
private static void testFileChannel() throws Exception {
......@@ -505,6 +507,27 @@ public class Transfer {
}
}
// Test that transferFrom with FileChannel source that is not readable
// throws NonReadableChannelException
static void xferTest09() throws Exception {
File source = File.createTempFile("source", null);
source.deleteOnExit();
File target = File.createTempFile("target", null);
target.deleteOnExit();
FileChannel fc1 = new FileOutputStream(source).getChannel();
FileChannel fc2 = new RandomAccessFile(target, "rw").getChannel();
try {
fc2.transferFrom(fc1, 0L, 0);
throw new RuntimeException("NonReadableChannelException expected");
} catch (NonReadableChannelException expected) {
} finally {
fc1.close();
fc2.close();
}
}
/**
* Creates file blah of specified size in bytes.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册