Tôi có đoạn mã sau để chèn "rose.gif" vào một roseNode. Nhưng làm cách nào để truy xuất tệp từ kho lưu trữ?Lấy tệp ra khỏi tệp JCR Node
Node roseNode = session.getRootNode().getNode("wiki:encyclopedia/wiki:entry[1]/");
File file = new File("rose.gif");
MimeTable mt = MimeTable.getDefaultTable();
String mimeType = mt.getContentTypeFor(file.getName());
if (mimeType == null) mimeType = "application/octet-stream";
Node fileNode = roseNode.addNode(file.getName(), "nt:file");
System.out.println(fileNode.getName());
Node resNode = fileNode.addNode("jcr:content", "nt:resource");
resNode.setProperty("jcr:mimeType", mimeType);
resNode.setProperty("jcr:encoding", "");
resNode.setProperty("jcr:data", new FileInputStream(file));
Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(file.lastModified());
resNode.setProperty("jcr:lastModified", lastModified);
//retrieve file and output as rose-out.gif
File outputFile = new File("rose-out.gif");
FileOutputStream out = new FileOutputStream(outputFile);
Xin chào Randall, những gì tôi muốn là một OutputStream và không phải là luồng đầu vào. Điều này có thể không? – Steve
Tôi đã tìm ra. Chỉ cần chuyển đổi inputStream thành một byte outputStream theo byte. – Steve
Đối với 2.0, tôi nghĩ bạn phải gọi Binary.dispose() khi bạn hoàn thành w/đối tượng nhị phân (http://www.day.com/specs/jcr/2.0/5_Reading.html). –