Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4435442

FileCacheImageOutputStream.close() does not remove cache file

XMLWordPrintable

    • beta2
    • generic
    • generic



      Name: mlR10151 Date: 04/09/2001



      The spec. for the FileCacheImageOutputStream.close() says:

      public void close() throws IOException
            Closes this FileCacheImageOututStream. All pending data is flushed to the output, and the cache
            file is closed and removed. The destination OutputStream is not closed.

      But the close() does not remove cache file.
      Though VM does remove the file on exit, the spec. says that file
      must be removed by the close() function.
      Note, that FileCacheImageInputStream.close() does remove the cache file.
      =========================== a.java ==============================
      import java.io.*;
      import javax.imageio.stream.*;

      public class a {
          public static void main (String argv[]) throws Exception {
              File f = new File("mytmpdir");
              if( !f.isDirectory() && !f.mkdir() ) {
                  System.out.println("Error: Can not create temporary directory");
                  return;
              }
          
              OutputStream ostream = new ByteArrayOutputStream();
              FileCacheImageOutputStream fcios = new FileCacheImageOutputStream(ostream, f);

              File[] before = f.listFiles();
              fcios.close();
              File[] after = f.listFiles();
          
              if( after.length + 1 != before.length ) {
                  System.out.println("Failed: temp file was not deleted:\n==== before ====");
                  for( int i = 0; i < before.length; i++ ) {
                      System.out.println(before[i].toString());
                  }

                  System.out.println("==== after ====");
                  for( int i = 0; i < after.length; i++ ) {
                      System.out.println(after[i].toString());
                  }
              } else {
                  System.out.println("Passed");
                  f.delete();
              }
          }
      }
      ===================== log =======================
      % java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b59)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b59, mixed mode)
      % java a
      Failed: temp file was not deleted:
      ==== before ====
      mytmpdir/imageio47588.tmp
      ==== after ====
      mytmpdir/imageio47588.tmp


      This bug causes failure of the new JCK test
      api/javax_imageio/stream/FileCacheImageOutputStream/index.html#Ctor

      ======================================================================

            dricesunw Daniel Rice (Inactive)
            mlsunw Ml Ml (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: