我说得对,当反思可以帮助。这里是我的代码,返回一个二进制存储在兔崽子数据存储的物理文件路径:
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();
}
是什么让你觉得'getStream()'创建临时文件? –
不是getStream()本身,但要使用它,我必须读取每个字节到内存中 – nico1510
你想要做什么,而不涉及到他们读入内存的那些blob? –