【问题标题】:JCR avoid file streamingJCR 避免文件流式传输
【发布时间】:2012-10-04 14:00:50
【问题描述】:

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

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

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

【问题讨论】:

  • 是什么让您认为getStream() 创建了临时文件?
  • 不是 getStream() 本身,但要使用它,我必须将每个字节读入内存
  • 你想对那些不涉及将它们读入内存的 blob 做什么?
  • 我想获取 blob 的绝对文件路径(不仅在数据存储中)并将其作为参数传递给外部程序。有没有办法(可能通过反射)从现有的文件流到达这个路径?因为文件流必须从某个地方获取流式传输字节的信息...
  • 您可能不想使用 JCR API 将文件传递到外部系统 - WebDAV 挂载(开箱即用 Jackrabbit)或 HTTP 可能更简单。例如,如果您通过 WebDAV 挂载 JCR 存储库,您将看到文件位于与 JCR 树中相同的路径。

标签: binary java-io jackrabbit jcr


【解决方案1】:

我说反思可能会有所帮助是对的。这是我的代码,它返回存储在 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();
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-20
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多