Hi,
Another code snippet for reading the contents of a file in a repository:
Session session = ...;
Node file = session.getRootNode().getNode("path/to/file");
InputStream content = file.getProperty("jcr:content/jcr:data").getStream();
try {
// read the content stream
} finally {
content.close();
}
Note that the above code works for typical nt:file/nt:resource nodes.
For more complex file structures you could use something like this:
InputStream getFileStream(Node file) throws ... {
Node resource = getFileResource(file);
return getResourceStream(resource);
}
Node getFileResource(Node file) throws... {
if (file.isNodeType("nt:file")) {
return file.getNode("jcr:content");
} else if (file.isNodeType("nt:linkedFile")) {
return file.getProperty("jcr:content").getNode();
} else {
// custom handling
}
}
InputStream getResourceStream(Node resource) throws {
if (resource.isNodeType("nt:resource")) {
return resource.getProperty("jcr:data").getStream();
} else {
// custom handling
}
}
You can also take a look at the IO handler abstraction used by the
Jackrabbit simple webdav feature.
BR,
Jukka Zitting