use of javax.jcr.Binary in project sling by apache.
the class GetNodeCommand method execute0.
@Override
protected byte[] execute0(Session session) throws RepositoryException, IOException {
Node node = session.getNode(getPath());
Property property;
if (node.hasProperty("jcr:data")) {
property = node.getProperty("jcr:data");
} else {
if (!node.hasNode("jcr:content")) {
return null;
}
Node contentNode = node.getNode("jcr:content");
if (!contentNode.hasProperty("jcr:data")) {
return null;
}
property = contentNode.getProperty("jcr:data");
}
if (property.getType() == PropertyType.BINARY) {
Binary binary = property.getBinary();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[2048];
InputStream stream = binary.getStream();
int read;
while ((read = stream.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
return out.toByteArray();
} finally {
binary.dispose();
}
}
return null;
}
Aggregations