|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
22 | 22 | */
|
23 | 23 |
|
24 | 24 | /* @test
|
25 |
| - * @bug 4434723 4482726 4559072 4795550 5081340 5103988 6984545 |
| 25 | + * @bug 4434723 4482726 4559072 4795550 5081340 5103988 6984545 8325382 |
26 | 26 | * @summary Test FileChannel.transferFrom and transferTo (use -Dseed=X to set PRNG seed)
|
27 | 27 | * @library ..
|
28 | 28 | * @library /test/lib
|
|
48 | 48 | import java.nio.channels.ServerSocketChannel;
|
49 | 49 | import java.nio.channels.SocketChannel;
|
50 | 50 | import java.nio.channels.spi.SelectorProvider;
|
| 51 | +import java.nio.file.Files; |
51 | 52 | import java.util.Random;
|
52 | 53 | import java.util.concurrent.TimeUnit;
|
53 | 54 |
|
54 | 55 | import jdk.test.lib.RandomFactory;
|
55 | 56 |
|
| 57 | +import org.testng.Assert; |
56 | 58 | import org.testng.annotations.Test;
|
57 | 59 |
|
58 | 60 | public class Transfer {
|
@@ -158,6 +160,33 @@ public void testReadableByteChannel() throws Exception {
|
158 | 160 | }
|
159 | 161 | }
|
160 | 162 |
|
| 163 | + @Test |
| 164 | + public void transferToNoThrow() throws IOException { // for bug 8325382 |
| 165 | + File source = File.createTempFile("before", "after"); |
| 166 | + source.deleteOnExit(); |
| 167 | + |
| 168 | + CharSequence csq = "Reality is greater than the sum of its parts."; |
| 169 | + Files.writeString(source.toPath(), csq); |
| 170 | + final long length = csq.length(); |
| 171 | + Assert.assertEquals(source.length(), length); |
| 172 | + |
| 173 | + File target = File.createTempFile("before", "after"); |
| 174 | + target.deleteOnExit(); |
| 175 | + |
| 176 | + try (FileInputStream in = new FileInputStream(source); |
| 177 | + FileOutputStream out = new FileOutputStream(target); |
| 178 | + FileChannel chSource = in.getChannel(); |
| 179 | + FileChannel chTarget = out.getChannel()) { |
| 180 | + // The count of bytes requested to transfer must exceed |
| 181 | + // FileChannelImpl.MAPPED_TRANSFER_THRESHOLD which is |
| 182 | + // currently 16384 |
| 183 | + long n = chSource.transferTo(length, 16385, chTarget); |
| 184 | + |
| 185 | + // At the end of the input so no bytes should be transferred |
| 186 | + Assert.assertEquals(n, 0); |
| 187 | + } |
| 188 | + } |
| 189 | + |
161 | 190 | @Test
|
162 | 191 | public void xferTest02() throws Exception { // for bug 4482726
|
163 | 192 | byte[] srcData = new byte[5000];
|
|
0 commit comments