本文整理汇总了Java中org.wso2.carbon.context.PrivilegedCarbonContext.getRegistry方法的典型用法代码示例。如果您正苦于以下问题:Java PrivilegedCarbonContext.getRegistry方法的具体用法?Java PrivilegedCarbonContext.getRegistry怎么用?Java PrivilegedCarbonContext.getRegistry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.context.PrivilegedCarbonContext
的用法示例。
在下文中一共展示了PrivilegedCarbonContext.getRegistry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Override
public void write(String outPath, InputStream in) throws MLOutputAdapterException {
if (in == null || outPath == null) {
throw new MLOutputAdapterException(String.format(
"Null argument values detected. Input stream: %s Out Path: %s", in, outPath));
}
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
IOUtils.copy(in, byteArrayOutputStream);
byte[] array = byteArrayOutputStream.toByteArray();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
Registry registry = carbonContext.getRegistry(RegistryType.SYSTEM_GOVERNANCE);
Resource resource = registry.newResource();
resource.setContent(array);
registry.put(outPath, resource);
} catch (RegistryException | IOException e) {
throw new MLOutputAdapterException(
String.format("Failed to save the model to registry %s: %s", outPath, e), e);
}
}
示例2: read
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Override
public InputStream read(String path) throws MLInputAdapterException {
try {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
Registry registry = carbonContext.getRegistry(RegistryType.SYSTEM_GOVERNANCE);
Resource resource = registry.get(path);
byte[] readArray = (byte[]) resource.getContent();
ByteArrayInputStream bis = new ByteArrayInputStream(readArray);
return bis;
} catch (RegistryException e) {
throw new MLInputAdapterException(String.format("Failed to read the model from uri %s: %s", path, e), e);
}
}