2012-10-04 62 views
1

在我的jackrabbit数据存储区中存储着大量的二进制文件。 我可以浏览数据存储文件系统并打开这些文件没有任何问题。JCR避免文件流式传输

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

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

+0

是什么让你觉得'getStream()'创建临时文件? –

+0

不是getStream()本身,但要使用它,我必须读取每个字节到内存中 – nico1510

+0

你想要做什么,而不涉及到他们读入内存的那些blob? –

回答

0

我说得对,当反思可以帮助。这里是我的代码,返回一个二进制存储在兔崽子数据存储的物理文件路径:

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 ""; 


} 

编辑:这是做它的正式方法(你必须使用兔崽子-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(); 
    }