[libbluray-devel] FileDescriptor: implement Java 8 Closeable interface

hpi1 git at videolan.org
Mon Nov 17 13:09:44 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | 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;
+            }
+        }
     }
 }



More information about the libbluray-devel mailing list