mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-25 15:20:11 +00:00
8276994: java/nio/channels/Channels/TransferTo.java leaves multi-GB files in /tmp
Reviewed-by: alanb
This commit is contained in:
parent
8aae88b0fc
commit
b0d7a9daa6
@ -138,27 +138,35 @@ public class TransferTo {
|
||||
*/
|
||||
@Test
|
||||
public void testMoreThanTwoGB() throws IOException {
|
||||
// preparing two temporary files which will be compared at the end of the test
|
||||
Path sourceFile = Files.createTempFile(null, null);
|
||||
Path targetFile = Files.createTempFile(null, null);
|
||||
Path sourceFile = Files.createTempFile("test2GBSource", null);
|
||||
try {
|
||||
// preparing two temporary files which will be compared at the end of the test
|
||||
Path targetFile = Files.createTempFile("test2GBtarget", null);
|
||||
try {
|
||||
// writing 3 GB of random bytes into source file
|
||||
for (int i = 0; i < NUM_WRITES; i++)
|
||||
Files.write(sourceFile, createRandomBytes(BYTES_PER_WRITE, 0), StandardOpenOption.APPEND);
|
||||
|
||||
// writing 3 GB of random bytes into source file
|
||||
for (int i = 0; i < NUM_WRITES; i++)
|
||||
Files.write(sourceFile, createRandomBytes(BYTES_PER_WRITE, 0), StandardOpenOption.APPEND);
|
||||
// performing actual transfer, effectively by multiple invocations of Filechannel.transferTo(FileChannel)
|
||||
long count;
|
||||
try (InputStream inputStream = Channels.newInputStream(FileChannel.open(sourceFile));
|
||||
OutputStream outputStream = Channels
|
||||
.newOutputStream(FileChannel.open(targetFile, StandardOpenOption.WRITE))) {
|
||||
count = inputStream.transferTo(outputStream);
|
||||
}
|
||||
|
||||
// performing actual transfer, effectively by multiple invocations of Filechannel.transferTo(FileChannel)
|
||||
long count;
|
||||
try (InputStream inputStream = Channels.newInputStream(FileChannel.open(sourceFile));
|
||||
OutputStream outputStream = Channels
|
||||
.newOutputStream(FileChannel.open(targetFile, StandardOpenOption.WRITE))) {
|
||||
count = inputStream.transferTo(outputStream);
|
||||
// comparing reported transferred bytes, must be 3 GB
|
||||
assertEquals(count, BYTES_WRITTEN);
|
||||
|
||||
// comparing content of both files, failing in case of any difference
|
||||
assertEquals(Files.mismatch(sourceFile, targetFile), -1);
|
||||
|
||||
} finally {
|
||||
Files.delete(targetFile);
|
||||
}
|
||||
} finally {
|
||||
Files.delete(sourceFile);
|
||||
}
|
||||
|
||||
// comparing reported transferred bytes, must be 3 GB
|
||||
assertEquals(count, BYTES_WRITTEN);
|
||||
|
||||
// comparing content of both files, failing in case of any difference
|
||||
assertEquals(Files.mismatch(sourceFile, targetFile), -1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user