United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 4894964 If ImageOutputStream.close() is not explicitly called, temp file is not deleted
4894964 : If ImageOutputStream.close() is not explicitly called, temp file is not deleted

Details
Type:
Bug
Submit Date:
2003-07-23
Status:
Closed
Updated Date:
2003-09-05
Project Name:
JDK
Resolved Date:
2003-09-05
Component:
client-libs
OS:
windows_2000
Sub-Component:
javax.imageio
CPU:
x86
Priority:
P4
Resolution:
Duplicate
Affected Versions:
1.4.2
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description

Name: gm110360			Date: 07/23/2003


FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
Using ImageIO.write() to write to an ImageOutputStream
results in a temporary file being created and never
deleted. The temp file is typically something like:
C:\Documents and Settings\<username>\Local
Settings\Temp\imageio8733.tmp

Explicitly calling ImageOutputStream.close() deletes the
temp file.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached sample program with an input image file
and an output image file name
2. Monitor your temp file directory and observe the new
imageioXXX.tmp file that remains after the program exits.

EXPECTED VERSUS ACTUAL BEHAVIOR :
The temp file should be cleaned up when the VM exits if
close() was not explicitly called.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.imageio.*;
import javax.imageio.stream.*;
import java.awt.image.*;
import java.io.*;

// ImageIO leaves a temp file around after exiting unless
ImageOutputStream.close() is called
// e.g. under W2K the file is something like C:\Documents and
Settings\<username>\Local Settings\Temp\imageio8733.tmp

public class ImageWriteCache {
	public static void main(String args[]) throws Exception {
		if (args.length != 2) {
			System.err.println("Usage: ImageWriteCache
<inputimagefile> <outputimagefile>");
			System.exit(1);
		}
		BufferedImage image = ImageIO.read(new File(args[0]));
		if (image == null) {
			System.err.println("Failed to load image " + args[0]);
			System.exit(1);
		}

		ImageOutputStream ios = ImageIO.createImageOutputStream(new
FileOutputStream(args[1]));
		if (ios == null || !ImageIO.write(image, "JPEG", ios)) {
			System.err.println("Failed to write image " + args[1]);
			System.exit(1);
		}

		// Uncomment this line and the temp file will be deleted
		//ios.close();
	}
}
---------- END SOURCE ----------
(Incident Review ID: 163578) 
======================================================================

                                    

Comments
EVALUATION



Name: abR10136			Date: 09/05/2003


   The temporary file is created by the instance of
   javax.imageio.steram.FileCacheImageOutputStream.
   This file is marked as "deleted on exit" as soon as it is created.
   If we do not close corresponding instance of
   FileCacheImageOutputStream the the temporary file is not closed and so
   it is not deleted on VM exit due to bug 4171239.

======================================================================
                                     
2004-08-21



Hardware and Software, Engineered to Work Together