Skip to content

Commit d3c43c2

Browse files
committed
8255937: Better cleanup for test/jdk/javax/imageio/stream/StreamFlush.java
Reviewed-by: jdv
1 parent b65ff60 commit d3c43c2

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

test/jdk/javax/imageio/stream/StreamFlush.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,8 @@
3434
import java.io.File;
3535
import java.io.FileOutputStream;
3636
import java.io.IOException;
37+
import java.nio.file.Files;
38+
import java.nio.file.Paths;
3739

3840
import javax.imageio.ImageIO;
3941
import javax.imageio.stream.ImageOutputStream;
@@ -44,14 +46,20 @@ public static void main(String[] args) throws IOException {
4446
ImageIO.setUseCache(true);
4547

4648
// Create a FileImageOutputStream from a FileOutputStream
47-
File temp1 = File.createTempFile("imageio", ".tmp");
48-
temp1.deleteOnExit();
49-
ImageOutputStream fios = ImageIO.createImageOutputStream(temp1);
50-
49+
File temp1 = File.createTempFile("StreamFlush_fis_", ".tmp");
5150
// Create a FileCacheImageOutputStream from a BufferedOutputStream
52-
File temp2 = File.createTempFile("imageio", ".tmp");
53-
temp2.deleteOnExit();
54-
FileOutputStream fos2 = new FileOutputStream(temp2);
51+
File temp2 = File.createTempFile("StreamFlush_bos_", ".tmp");
52+
try (ImageOutputStream fios = ImageIO.createImageOutputStream(temp1);
53+
FileOutputStream fos2 = new FileOutputStream(temp2)) {
54+
test(temp1, fios, temp2, fos2);
55+
} finally {
56+
Files.delete(Paths.get(temp1.getAbsolutePath()));
57+
Files.delete(Paths.get(temp2.getAbsolutePath()));
58+
}
59+
}
60+
61+
private static void test(File temp1, ImageOutputStream fios, File temp2,
62+
FileOutputStream fos2) throws IOException {
5563
BufferedOutputStream bos = new BufferedOutputStream(fos2);
5664
ImageOutputStream fcios1 = ImageIO.createImageOutputStream(bos);
5765

0 commit comments

Comments
 (0)