KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > stream > CloseableDisposerRecord


1 /*
2  * @(#)CloseableDisposerRecord.java 1.1 05/11/23
3  *
4  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.imageio.stream;
9
10 import java.io.Closeable JavaDoc;
11 import java.io.IOException JavaDoc;
12 import sun.java2d.DisposerRecord;
13
14 /**
15  * Convenience class that closes a given resource (e.g. RandomAccessFile),
16  * typically associated with an Image{Input,Output}Stream, prior to the
17  * stream being garbage collected.
18  */

19 public class CloseableDisposerRecord implements DisposerRecord {
20     private Closeable JavaDoc closeable;
21
22     public CloseableDisposerRecord(Closeable JavaDoc closeable) {
23         this.closeable = closeable;
24     }
25
26     public synchronized void dispose() {
27         if (closeable != null) {
28             try {
29                 closeable.close();
30             } catch (IOException JavaDoc e) {
31             } finally {
32                 closeable = null;
33             }
34         }
35     }
36 }
37
Popular Tags