jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java
changeset 3448 1ccef37a150f
parent 2 90ce3da70b43
child 5506 202f599c92aa
--- a/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java	Fri May 08 15:38:21 2009 +0400
+++ b/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java	Fri May 08 15:57:33 2009 +0400
@@ -48,6 +48,10 @@
     // Pos after last (rightmost) byte written
     private long maxStreamPos = 0L;
 
+    /** The CloseAction that closes the stream in
+     *  the StreamCloser's shutdown hook                     */
+    private final StreamCloser.CloseAction closeAction;
+
     /**
      * Constructs a <code>FileCacheImageOutputStream</code> that will write
      * to a given <code>outputStream</code>.
@@ -82,7 +86,9 @@
         this.cacheFile =
             File.createTempFile("imageio", ".tmp", cacheDir);
         this.cache = new RandomAccessFile(cacheFile, "rw");
-        StreamCloser.addToQueue(this);
+
+        this.closeAction = StreamCloser.createCloseAction(this);
+        StreamCloser.addToQueue(closeAction);
     }
 
     public int read() throws IOException {
@@ -227,7 +233,7 @@
         cacheFile = null;
         stream.flush();
         stream = null;
-        StreamCloser.removeFromQueue(this);
+        StreamCloser.removeFromQueue(closeAction);
     }
 
     public void flushBefore(long pos) throws IOException {