1 Reply Latest reply on Mar 31, 2010 8:23 PM by darrylburke

    Temporary Files Stay when using ImageDecoder

      I am trying to write a java program to take a TIFF image and display it on the screen. The code seems to work just fine, as I can see the image. The problem is that this code creates a temporary file and that temp file hangs around forever, even after the program is closed. In our situation, these images should be considered confidential, and leaving a copy of them lying around is a security concern.

      Is there any way I can ensure that the temporary file created by this code gets deleted either when it is no longer used, or at least when the program terminates?

      My code now reads:

      InputStream stream = new ByteArrayInputStream(image_data);
      ImageDecoder dec = ImageCodec.createImageDecoder("TIFF", stream, null);
      RenderedImage ri = null;
      ri = dec.decodeAsRenderedImage(0);
      }catch(Exception e){
      // code to handle exception for invalid images

      In this code, image_data is a byte[] array with my TIFF image data, and after this snippet I then take the rendered image and scale it and add it to a display panel.

      The temporary file in question is created with 0 bytes during the createImageDecoder() call, and the TIFF image data is dumped into that temporary file with the decodeAsRenderedImage() call. The file has a name like "jai-FCSS-XXXX.tmp", where the XXXX is a series of (more than 4) numbers. It is created in the folder specified by the system property "java.io.tmpdir". I am using NetBeans 6.5.1.

      It appears to me that when that temporary file is created by the createImageDecoder() call, that deleteOnExit() is not then invoked on that file, to ensure the file is deleted when the program exits.

      Is there a way to ensure that temporary file gets deleted by the time my program exits, or has this problem already been fixed in a later update to java or NetBeans?

      Thank you in advance,

      Edited by: GeneralHQ on Mar 31, 2010 11:41 AM