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
3434import java .io .File ;
3535import java .io .FileOutputStream ;
3636import java .io .IOException ;
37+ import java .nio .file .Files ;
38+ import java .nio .file .Paths ;
3739
3840import javax .imageio .ImageIO ;
3941import 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