1

在我的 jackrabbit 数据存储中,存储了大型二进制文件。我可以浏览数据存储文件系统并毫无问题地打开这些文件。

现在如何在我的应用程序中使用这些文件?我当然可以使用 jcr.binary 类型的 getStream() 方法,但是我会将已经存在的文件的所有内容流式传输到一个新的临时文件中,对吗?由于我的二进制文件非常大,我不想要那个。我正在寻找一种方法来获取二进制文件的完整文件系统路径。jcr.Property 的 getpath() 方法只返回存储库中的路径,并且只返回映射的节点名称,而不是真正存储在我的文件系统上的节点名称。一般来说,我必须将二进制对象解析为 Java.IO.File 对象,并且我想避免 Streaming

编辑:通过反射我看到我的二进制类是类 org.apache.jackrabbit.core.value.BLOBInDataStore 我想我必须以某种方式从那里访问 File 值

4

1 回答 1

0

当我说反思可能会有所帮助时,我是对的。这是我的代码,它返回存储在 jackrabbit 数据存储中的二进制文件的物理文件路径:

public String getPhysicalBinaryPath(Binary b){
    try {
        Field idField=b.getClass().getDeclaredField("identifier");
        idField.setAccessible(true);
        String identifier = (String)idField.get(b).toString();
        Field storeField=b.getClass().getDeclaredField("store");
        storeField.setAccessible(true);
        Object store = storeField.get(b);
        Field pathField = store.getClass().getDeclaredField("path");
        pathField.setAccessible(true);
        String dataStorePath = (String)pathField.get(store);

        String binaryPath = identifier.substring(0,2)+File.separator+
                            identifier.substring(2,4)+File.separator+
                            identifier.substring(4,6)+File.separator+
                            identifier;

        return dataStorePath+File.separator+binaryPath;

    } catch (IllegalArgumentException ex) {
        Logger.getLogger(Repoutput.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(Repoutput.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchFieldException ex) {
        Logger.getLogger(Repoutput.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        Logger.getLogger(Repoutput.class.getName()).log(Level.SEVERE, null, ex);
    }

        return "";


}

编辑:这是官方的做法(你必须使用jackrabbit-api)

Binary b = session.getValueFactory().createBinary(in);
Value value = session.getValueFactory().createValue(b);
  if (value instanceof JackrabbitValue) {
   JackrabbitValue jv = (JackrabbitValue) value;
   String id = jv.getContentIdentity();
  }
于 2012-10-05T06:42:27.337 回答