本文整理汇总了Java中javax.jcr.Binary.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java Binary.dispose方法的具体用法?Java Binary.dispose怎么用?Java Binary.dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jcr.Binary
的用法示例。
在下文中一共展示了Binary.dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import javax.jcr.Binary; //导入方法依赖的package包/类
private byte[] get(final String path) throws LoginException, RepositoryException, IOException {
byte[] ret = null;
Session session = null;
try {
session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
Binary b = session.getRootNode().getProperty(path).getBinary();
ret = IOUtils.toByteArray(b.getStream());
b.dispose();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
session.logout();
}
}
return ret;
}
示例2: putFile
import javax.jcr.Binary; //导入方法依赖的package包/类
private Node putFile(
Node parent, String name, String mime,
InputStream data) throws RepositoryException {
Binary binary = parent.getSession().getValueFactory().createBinary(data);
try {
Node file = getOrAddNode(parent, name, NodeType.NT_FILE);
//oak:Resource is non referenceable hence less overhead
String nodeType = useOakResource ? "oak:Resource" : NodeType.NT_RESOURCE;
Node content = getOrAddNode(file, Node.JCR_CONTENT, nodeType);
content.setProperty(Property.JCR_MIMETYPE, mime);
String[] parameters = mime.split(";");
for (int i = 1; i < parameters.length; i++) {
int equals = parameters[i].indexOf('=');
if (equals != -1) {
String parameter = parameters[i].substring(0, equals);
if ("charset".equalsIgnoreCase(parameter.trim())) {
content.setProperty(
Property.JCR_ENCODING,
parameters[i].substring(equals + 1).trim());
}
}
}
content.setProperty(Property.JCR_LAST_MODIFIED, Calendar.getInstance());
content.setProperty(Property.JCR_DATA, binary);
return file;
} finally {
binary.dispose();
}
}