[libbluray-devel] Mount Xlet home directory to cache

hpi1 git at videolan.org
Wed Nov 5 13:00:21 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Nov  5 13:47:40 2014 +0200| [7368c32205302f5c16fc637083c91e07983970e5] | committer: hpi1

Mount Xlet home directory to cache

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=7368c32205302f5c16fc637083c91e07983970e5
---

 src/libbluray/bdj/java/java/awt/BDToolkitBase.java |   13 +++--
 src/libbluray/bdj/java/java/io/BDFileSystem.java   |   13 +++--
 .../bdj/java/java/io/FileInputStream.java          |   48 ++++------------
 .../bdj/java/org/videolan/BDJXletContext.java      |   58 +++++++++++++-------
 4 files changed, 64 insertions(+), 68 deletions(-)

diff --git a/src/libbluray/bdj/java/java/awt/BDToolkitBase.java b/src/libbluray/bdj/java/java/awt/BDToolkitBase.java
index e3620c4..ba837ab 100644
--- a/src/libbluray/bdj/java/java/awt/BDToolkitBase.java
+++ b/src/libbluray/bdj/java/java/awt/BDToolkitBase.java
@@ -144,10 +144,15 @@ abstract class BDToolkitBase extends Toolkit {
 
     public Image createImage(String filename) {
         if (!new File(filename).isAbsolute()) {
-            URL url = BDJXletContext.getCurrentResource(filename);
-            if (url != null) {
-                logger.warning("" + filename + " translated to " + url);
-                return createImage(url);
+            String home = BDJXletContext.getCurrentXletHome();
+            if (home != null) {
+                String homeFile = home + filename;
+                if (new File(homeFile).exists()) {
+                    logger.warning("resource translated to " + homeFile);
+                    filename = homeFile;
+                } else {
+                    logger.error("resource " + homeFile + " does not exist");
+                }
             }
         }
 
diff --git a/src/libbluray/bdj/java/java/io/BDFileSystem.java b/src/libbluray/bdj/java/java/io/BDFileSystem.java
index 31bfb77..39478e2 100644
--- a/src/libbluray/bdj/java/java/io/BDFileSystem.java
+++ b/src/libbluray/bdj/java/java/io/BDFileSystem.java
@@ -133,15 +133,16 @@ public abstract class BDFileSystem extends FileSystem {
             return fs.getBooleanAttributes(f);
         }
 
-        /* try to locate file in Xlet home directory (inside JAR file) */
-        URL url = BDJXletContext.getCurrentResource(f.getPath());
-        if (url == null) {
+        /* try to locate file in Xlet home directory */
+        String home = BDJXletContext.getCurrentXletHome();
+        if (home == null) {
+            logger.error("no home found for " + f.getPath() + " at " + logger.dumpStack());
             return 0;
         }
 
-        logger.info("Relative path " + f.getPath() + " translated to " + url);
-
-        return FileSystem.BA_EXISTS; //|BA_REGULAR
+        String path = home + f.getPath();
+        logger.info("Relative path " + f.getPath() + " translated to " + path);
+        return fs.getBooleanAttributes(new File(path));
     }
 
     /*
diff --git a/src/libbluray/bdj/java/java/io/FileInputStream.java b/src/libbluray/bdj/java/java/io/FileInputStream.java
index 71aa059..b9c0e5f 100644
--- a/src/libbluray/bdj/java/java/io/FileInputStream.java
+++ b/src/libbluray/bdj/java/java/io/FileInputStream.java
@@ -63,7 +63,16 @@ public class FileInputStream extends InputStream
         } else {
             /* relative paths are problematic ... */
             /* Those should be mapped to xlet home directory, which is inside .jar file. */
-            openResource(name);
+
+            String home = BDJXletContext.getCurrentXletHome();
+            if (home == null) {
+                if (logger == null) {
+                    logger = Logger.getLogger(FileInputStream.class.getName());
+                }
+                logger.error("no home found for " + name + " at " + logger.dumpStack());
+                throw new FileNotFoundException(name);
+            }
+            open(home + name);
         }
 
         available = 1024;
@@ -86,43 +95,6 @@ public class FileInputStream extends InputStream
         available = 1024;
     }
 
-    private void openResource(String name) throws FileNotFoundException {
-        if (logger == null) {
-            logger = Logger.getLogger(FileInputStream.class.getName());
-        }
-
-        /* J2SE URL.getPath() returns file:/xxx.jar!/... for jar resource urls ... */
-        if (name.indexOf("file:") == 0 && name.indexOf(".jar!/") > 0) {
-            logger.error("Fixing invalid resource url: " + name);
-            name = name.substring(name.indexOf(".jar!") + 6);
-        }
-
-        /* try to locate file in Xlet home directory (inside JAR file) */
-
-        ClassLoader cldr = (ClassLoader)BDJXletContext.getCurrentClassLoader();
-        if (cldr == null) {
-            throw new FileNotFoundException(name);
-        }
-
-        if (name.startsWith("./") || name.startsWith(".\\")) {
-            name = name.substring(2);
-        }
-
-        URL url = cldr.getResource(name);
-        if (url == null) {
-            logger.error("Resource not found: " + name);
-            throw new FileNotFoundException(name);
-        }
-        logger.info(name + " translated to " + url);
-
-        fd.slave = cldr.getResourceAsStream(name);
-        if (fd.slave == null) {
-            logger.error("Error getting resource as stream");
-            throw new FileNotFoundException(name);
-        }
-    }
-
-
     private native void open(String name) throws FileNotFoundException;
     private native int  readBytes(byte b[], int off, int len) throws IOException;
     private native int  close0();
diff --git a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
index 65a6281..7f6f757 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
@@ -54,6 +54,39 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi
                                               this);
 
         callbackQueue = new BDJActionQueue(this.threadGroup, "CallbackQueue");
+
+        mountHomeDir(entry);
+    }
+
+    private void mountHomeDir(AppEntry entry) {
+        String home = entry.getBasePath();
+        if (home.length() > 5) {
+            // TODO: may be located deeper inside jar, not root ?
+            logger.error("Unhandled home directory: " + home);
+        }
+        try {
+            int homeJarID = Integer.parseInt(home);
+            long time = System.currentTimeMillis();
+            homeMountPoint = MountManager.mount(homeJarID, false) + java.io.File.separator;
+            time = System.currentTimeMillis() - time;
+            logger.info("Mounted Xlet home directory from " + home + ".jar " +
+                        "to " + homeMountPoint + "(" + time + "ms)");
+        } catch (Exception ex) {
+            logger.error("Failed mounting " + home + ".jar:" + ex);
+        }
+    }
+
+    public String getXletHome() {
+        return homeMountPoint;
+    }
+
+    public static String getCurrentXletHome() {
+        BDJXletContext ctx = BDJXletContext.getCurrentContext();
+        if (ctx == null) {
+            logger.error("getCurrentXletHome(): no context: " + Logger.dumpStack());
+            return null;
+        }
+        return ctx.getXletHome();
     }
 
     public Object getXletProperty(String key) {
@@ -119,26 +152,6 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi
         return cldr;
     }
 
-    public static URL getCurrentResource(String path)
-    {
-        ClassLoader cldr = (ClassLoader)BDJXletContext.getCurrentClassLoader();
-        if (cldr == null) {
-            return null;
-        }
-
-        if (path.startsWith("./") || path.startsWith(".\\")) {
-            path = path.substring(2);
-        }
-
-        URL url = cldr.getResource(path);
-        if (url == null) {
-            logger.error("getCurrentResource(): " + path + " not found: " + Logger.dumpStack());
-            return null;
-        }
-
-        return url;
-    }
-
     /*
      *
      */
@@ -425,11 +438,16 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi
             defaultLooks = null;
             released = true;
         }
+
+        // Do not unmount home directory here, it is likely to be used multiple times during disc playback.
+        // All .jars are unmounted at BD-J shutdown.
+        //MountManager.unmount(homeJarID);
     }
 
     private boolean released = false;
     private String[] args;
     private AppID appid;
+    private String homeMountPoint = null;
     private BDJClassLoader loader;
     private Container container;
     private EventQueue eventQueue = null;



More information about the libbluray-devel mailing list