libbluray | branch: master | hpi1 <[email protected]> | Mon Nov 17 11:14:28 2014 +0200| [e9b3af4ed30795ee560f9b79737f41c2e2e77ae0] | committer: hpi1
FileDescriptor: implement Java 8 Closeable interface > http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=e9b3af4ed30795ee560f9b79737f41c2e2e77ae0 --- src/libbluray/bdj/java/java/io/FileDescriptor.java | 33 +++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/libbluray/bdj/java/java/io/FileDescriptor.java b/src/libbluray/bdj/java/java/io/FileDescriptor.java index 44a1888..59a2c4f 100644 --- a/src/libbluray/bdj/java/java/io/FileDescriptor.java +++ b/src/libbluray/bdj/java/java/io/FileDescriptor.java @@ -18,6 +18,10 @@ package java.io; +import java.util.Iterator; +import java.util.List; +import java.util.ArrayList; + public final class FileDescriptor { /* for files used by JVM */ @@ -76,9 +80,36 @@ public final class FileDescriptor { } /* Java 8 */ - void attach(Closeable c) { + + private List parents = null; + private boolean closed = false; + + synchronized void attach(Closeable c) { + if (parents == null) { + parents = new ArrayList(); + } + parents.add(c); } synchronized void closeAll(Closeable releaser) throws IOException { + if (!closed) { + IOException ex = null; + closed = true; + + for (Iterator it = parents.iterator(); it.hasNext(); ) { + Closeable c = (Closeable)it.next(); + try { + c.close(); + } catch (IOException ioe) { + if (ex != null) + ex = ioe; + } + } + + releaser.close(); + if (ex != null) { + throw ex; + } + } } } _______________________________________________ libbluray-devel mailing list [email protected] https://mailman.videolan.org/listinfo/libbluray-devel
