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)
======================================================================