[libbluray-devel] BDFileSystem: fix createFileExclusivelyImpl() with some Java6 versions
hpi1
git at videolan.org
Fri Jan 24 20:30:03 CET 2014
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Jan 24 11:38:39 2014 +0200| [40f9e7fe704fef998c0fd4fb386c41769a830e9d] | committer: hpi1
BDFileSystem: fix createFileExclusivelyImpl() with some Java6 versions
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=40f9e7fe704fef998c0fd4fb386c41769a830e9d
---
src/libbluray/bdj/java/java/io/BDFileSystem.java | 59 +++++++++++++++++++---
1 file changed, 51 insertions(+), 8 deletions(-)
diff --git a/src/libbluray/bdj/java/java/io/BDFileSystem.java b/src/libbluray/bdj/java/java/io/BDFileSystem.java
index 2cac57f..e99d9d0 100644
--- a/src/libbluray/bdj/java/java/io/BDFileSystem.java
+++ b/src/libbluray/bdj/java/java/io/BDFileSystem.java
@@ -27,12 +27,18 @@
package java.io;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
import java.net.URL;
import org.videolan.BDJXletContext;
+import org.videolan.Logger;
public abstract class BDFileSystem extends FileSystem {
+ private static final Logger logger = Logger.getLogger(BDFileSystem.class.getName());
+
protected final FileSystem fs;
public static void init(Class c) {
@@ -90,7 +96,7 @@ public abstract class BDFileSystem extends FileSystem {
public String resolve(File f) {
if (!f.isAbsolute()) {
- System.err.println("***** resolve " + f);
+ System.err.println("***** resolve " + f + " -> " + fs.resolve(f));
}
return fs.resolve(f);
}
@@ -110,7 +116,7 @@ public abstract class BDFileSystem extends FileSystem {
return 0;
}
- org.videolan.Logger.getLogger("BDFileSystem").info("Relative path " + f.getPath() + " translated to " + url);
+ logger.info("Relative path " + f.getPath() + " translated to " + url);
return FileSystem.BA_EXISTS; //|BA_REGULAR
}
@@ -133,8 +139,50 @@ public abstract class BDFileSystem extends FileSystem {
public abstract boolean setPermission(File f, int access, boolean enable, boolean owneronly);
*/
+ /* this version exists in some java6 versions.
+ * Use reflection to make sure build succees and right method is called.
+ */
+ public boolean createFileExclusively(String path, boolean restrictive) throws IOException {
+ return createFileExclusivelyImpl(path, restrictive);
+ }
+ /* this version exists in most java versions (1.4, 1.7, some 1.6 versions) */
public boolean createFileExclusively(String path) throws IOException {
- return fs.createFileExclusively(path);
+ return createFileExclusivelyImpl(path, false);
+ }
+
+ private boolean createFileExclusivelyImpl(String path, boolean restrictive) throws IOException {
+ Method m;
+ Object[] args;
+
+ /* resolve method and set up arguments */
+ try {
+ try {
+ m = fs.getClass().getDeclaredMethod("createFileExclusively", new Class[] { String.class });
+ args = new Object[] {(Object)path};
+ } catch (NoSuchMethodException e) {
+ m = fs.getClass().getDeclaredMethod("createFileExclusively", new Class[] { String.class, boolean.class });
+ args = new Object[] {(Object)path, (Object)new Boolean(restrictive)};
+ }
+ } catch (NoSuchMethodException e) {
+ logger.error("no matching FileSystem.createFileExclusively found !");
+ throw new IOException();
+ }
+
+ /* call */
+ try {
+ Boolean result = (Boolean)m.invoke(fs, args);
+ return result.booleanValue();
+ } catch (IllegalAccessException e) {
+ logger.error("" + e);
+ throw new IOException();
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getTargetException();
+ if (t instanceof IOException) {
+ throw (IOException)t;
+ }
+ logger.error("" + t);
+ throw new IOException();
+ }
}
/*
@@ -175,11 +223,6 @@ public abstract class BDFileSystem extends FileSystem {
return fs.listRoots();
}
- /*
- SE only
- public abstract long getSpace(File f, int t);
- */
-
public int compare(File f1, File f2) {
return fs.compare(f1, f2);
}
More information about the libbluray-devel
mailing list