1
1
/*
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.
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
34
34
import java .io .File ;
35
35
import java .io .FileOutputStream ;
36
36
import java .io .IOException ;
37
+ import java .nio .file .Files ;
38
+ import java .nio .file .Paths ;
37
39
38
40
import javax .imageio .ImageIO ;
39
41
import javax .imageio .stream .ImageOutputStream ;
@@ -44,14 +46,20 @@ public static void main(String[] args) throws IOException {
44
46
ImageIO .setUseCache (true );
45
47
46
48
// 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" );
51
50
// 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 {
55
63
BufferedOutputStream bos = new BufferedOutputStream (fos2 );
56
64
ImageOutputStream fcios1 = ImageIO .createImageOutputStream (bos );
57
65
0 commit comments