Skip to content
Permalink
Browse files
8276994: java/nio/channels/Channels/TransferTo.java leaves multi-GB f…
…iles in /tmp

Reviewed-by: alanb
  • Loading branch information
Lance Andersen committed Nov 11, 2021
1 parent 8aae88b commit b0d7a9daa6ceb1959bc701043fe3f0397d2ba6f7
Showing with 28 additions and 20 deletions.
  1. +28 −20 test/jdk/java/nio/channels/Channels/TransferTo.java
@@ -138,27 +138,35 @@ public void testStreamContents(InputStreamProvider inputStreamProvider,
*/
@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);

// 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);
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);

// 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);
}

/*

1 comment on commit b0d7a9d

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on b0d7a9d Nov 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.