다음 코드를 사용하여 "rose.gif"를 roseNode에 삽입합니다. 하지만 저장소에서 파일을 검색하려면 어떻게해야합니까? 노드와의 파일의 내용 "JCR : 데이터를"속성을에 :JCR 파일 노드에서 파일 가져 오기
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);
Hi Randall, 내가 원하는 것은 OutputStream이고 입력 스트림이 아닙니다. 이것이 가능한가? – Steve
나는 그것을 이해했다. 그냥 inputStream을 바이트 단위로 outputStream 바이트로 변환했다. – Steve
2.0의 경우 Binary 객체 (http://www.day.com/specs/jcr/2.0/5_Reading.html)를 사용하면 Binary.dispose()를 호출해야한다고 생각합니다. –