当前位置: 首页>>代码示例>>Java>>正文


Java Resource.getContentStream方法代码示例

本文整理汇总了Java中org.wso2.carbon.registry.core.Resource.getContentStream方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.getContentStream方法的具体用法?Java Resource.getContentStream怎么用?Java Resource.getContentStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.wso2.carbon.registry.core.Resource的用法示例。


在下文中一共展示了Resource.getContentStream方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testContentStreaming

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testContentStreaming() throws Exception {


        Resource r3 = registry.newResource();
        String path = "/content/stream/content.txt";
        r3.setContent(RegistryUtils.encodeString("this is the content"));
        r3.setDescription("this is test desc");
        r3.setMediaType("plain/text");
        r3.setProperty("test2", "value2");
        r3.setProperty("test1", "value1");
        registry.put(path, r3);

        Resource r4 = registry.get("/content/stream/content.txt");

        assertEquals("Content is not equal.", RegistryUtils.decodeBytes((byte[]) r3.getContent()),
                RegistryUtils.decodeBytes((byte[]) r4.getContent()));

        InputStream isTest = r4.getContentStream();

        assertEquals("Content stream is not equal.", RegistryUtils.decodeBytes((byte[]) r3.getContent()),
                convertStreamToString(isTest));

        r3.discard();
    }
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:25,代码来源:TestContentStream.java

示例2: getTemplatePolicy

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
 * Read the template policy from registry according to level at which
 * throttling is engaged
 *
 * @param level - global, service or operation level..
 * @return template OMElement
 * @throws ThrottleComponentException - error on reading template
 */
private OMElement getTemplatePolicy(String level) throws ThrottleComponentException {
    XMLStreamReader parser;
    String resourceUri = ThrottleComponentConstants.TEMPLATE_URI + level;
    try {
        //Get the input stream of the template policy from registry
        Resource resource;
        Registry registry = getConfigSystemRegistry();
        if (registry.resourceExists(resourceUri)) {
            resource = registry.get(resourceUri);
        } else {
            throw new ThrottleComponentException("templateNotFound");
        }
        InputStream in = resource.getContentStream();

        //Get the template policy element by parsing the input stream
        parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
    } catch (Exception e) {
        log.error("Error occoured while loading template from registry", e);
        throw new ThrottleComponentException("errorLoadingTemplate");
    }
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    return builder.getDocumentElement();
}
 
开发者ID:wso2-attic,项目名称:carbon-qos,代码行数:32,代码来源:ThrottleConfigAdminService.java

示例3: loadPolicy

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException, XMLStreamException {

        InputStream in = resource.getContentStream();
        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();

        xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        xmlInputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
        XMLStreamReader parser = xmlInputFactory.createXMLStreamReader(in);
        StAXOMBuilder builder = new StAXOMBuilder(parser);

        OMElement policyElement = builder.getDocumentElement();
        return PolicyEngine.getPolicy(policyElement);

    }
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:15,代码来源:SecurityDeploymentInterceptor.java

示例4: loadPolicy

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException,
        XMLStreamException {

    InputStream in = resource.getContentStream();
    XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
    xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
    XMLStreamReader parser = xmlInputFactory.createXMLStreamReader(in);
    StAXOMBuilder builder = new StAXOMBuilder(parser);

    OMElement policyElement = builder.getDocumentElement();
    return PolicyEngine.getPolicy(policyElement);

}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:14,代码来源:SecurityConfigAdmin.java

示例5: getPropertyLength

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
 * Utility function to retrieve the length of a property of a Registry <code>Node</code>.
 *
 * @param node
 * @param propertyName
 * @return
 * @throws RegistryException
 */	
protected static long getPropertyLength(Resource node, String propertyName) throws RegistryException {
    String property = node.getProperty(propertyName);
    //if property asks for REGISTRY_DATA then this should return the length of the content stream //my assumption
    if(propertyName.equals(CMISConstants.GREG_DATA)){
        if(property != null && !property.equals("true")){
            return 0;
        }
    	long count = 0;
        //node.getContent();
        Object dataObject = node.getContent();

    	if(dataObject == null){
    		return count;
    	} else{
            count = 0;
            byte[] buffer = new byte[64 * 1024];
            InputStream inputStream = node.getContentStream();
            try {
                int b = inputStream.read(buffer);
                while (b > -1) {
                    count += b;
                    b = inputStream.read(buffer);
                }
                inputStream.close();
            } catch (IOException e) {
                throw new CmisRuntimeException(e.getMessage(),e);
            }
            return count;
    	}
    	
    } else{
        if(property == null){
            return -1;
        } else{
    	    return property.length();
        }
    }
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:47,代码来源:RegistryObject.java

示例6: getByteContent

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static byte[] getByteContent(Resource resource, String sourceURL)
                        throws RegistryException {
	try {
		InputStream is = null;
		if (sourceURL != null) {
			is = new URL(sourceURL).openStream();
		} else {
               Object content = resource.getContent();
               if( null == content) {
                   //returning an empty array, rather than 'null'.
                   return new byte[0];
               }
               is = resource.getContentStream();
			if (is == null) {
                   if (content instanceof byte[]) {
                       return (byte[]) content;
                   } else if (content instanceof String) {
                       return RegistryUtils.encodeString((String) content);
                   } else {
                       throw new RegistryException("Unknown type found as content " + content);
                   }
               }
		}
		return readBytesFromInputSteam(is);
	} catch (IOException e) {
		throw new RegistryException("Error at indexing", e);
	}
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:29,代码来源:IndexingUtils.java

示例7: makeDataHandler

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static DataHandler makeDataHandler(Resource resource, File tempFile) throws IOException, RegistryException{
        if (resource.getContent() == null) {
            return null;
        }
        InputStream is = null;
        OutputStream os = null;
        try {
            os = new FileOutputStream(tempFile);
            if (resource.getContent() instanceof String[]) {
                String[] strArray = (String[]) resource.getContent();

                ObjectOutputStream oos = new ObjectOutputStream(os);
                oos.writeObject(strArray);
            } else {
                try {
                    is = resource.getContentStream();
//                    os = new FileOutputStream(tempFile);

                    byte[] buffer = new byte[4096];
                    for (int n; (n = is.read(buffer)) != -1; )
                        os.write(buffer, 0, n);
                    os.flush();
                } finally {
                    if (is != null) {
                        is.close();
                    }
                }
            }
        } finally {
            if (os != null) {
                os.close();
            }
        }
        //         Base64Binary base64Binary = new Base64Binary();
        return new DataHandler(new FileDataSource(tempFile));
    }
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:37,代码来源:CommonUtil.java

示例8: makeDataHandler

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static DataHandler makeDataHandler(Resource resource, File tempFile) throws IOException, RegistryException{
	if ((resource instanceof Collection) || (resource.getContent() == null)) {
		return null;
	}
	InputStream is = null;
	OutputStream os = null;
	try {
		os = new FileOutputStream(tempFile);
		if (resource.getContent() instanceof String[]
		                                            && !(resource.getContent() instanceof String)) { // To accommodate collections and ratings
			String[] strArray = (String[]) resource.getContent();

			ObjectOutputStream oos = new ObjectOutputStream(os);
			oos.writeObject(strArray);
		} else {
			try {
				is = resource.getContentStream();
				//                    os = new FileOutputStream(tempFile);

				byte[] buffer = new byte[4096];
				for (int n; (n = is.read(buffer)) != -1; )
					os.write(buffer, 0, n);
				os.flush();
			} finally {
				if (is != null) {
					is.close();
				}
			}
		}
	} finally {
		if (os != null) {
			os.close();
		}
	}
	//         Base64Binary base64Binary = new Base64Binary();
	return new DataHandler(new FileDataSource(tempFile));
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:38,代码来源:WSRegistryClientUtils.java

示例9: ResourceContentInputStream

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public ResourceContentInputStream(Resource resource) throws RegistryException {
    this.resource = resource;
    inputStream = resource.getContentStream();
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:5,代码来源:ResourceContentInputStream.java

示例10: getInputStreamFromPath

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
 * Creates and returns an InputStream from the file path / http location given.
 *
 * @throws DataServiceFault
 * @see InputStream
 */
public static InputStream getInputStreamFromPath(String path) throws IOException,
        DataServiceFault {
    InputStream ins;
    /*
        Security Comment :
        This path is trustworthy, path is configured in the dbs file.
     */
    if (path.startsWith("http://")) {
        /* This is a url file path */
        URL url = new URL(path);
        ins = url.openStream();
    } else if (isRegistryPath(path)) {
        try {
            RegistryService registryService = DataServicesDSComponent.getRegistryService();
            if (registryService == null) {
                throw new DataServiceFault("DBUtils.getInputStreamFromPath(): Registry service is not available");
            }
            Registry registry;
            if (path.startsWith(DBConstants.CONF_REGISTRY_PATH_PREFIX)) {
                if (path.length() > DBConstants.CONF_REGISTRY_PATH_PREFIX.length()) {
                    path = path.substring(DBConstants.CONF_REGISTRY_PATH_PREFIX.length());
                    registry = registryService.getConfigSystemRegistry(getCurrentTenantId());
                } else {
                    throw new DataServiceFault("Empty configuration registry path given");
                }
            } else {
                if (path.length() > DBConstants.GOV_REGISTRY_PATH_PREFIX.length()) {
                    path = path.substring(DBConstants.GOV_REGISTRY_PATH_PREFIX.length());
                    registry = registryService.getGovernanceSystemRegistry(getCurrentTenantId());
                } else {
                    throw new DataServiceFault("Empty governance registry path given");
                }
            }
            if (registry.resourceExists(path)) {
                Resource serviceResource = registry.get(path);
                ins = serviceResource.getContentStream();
            } else {
                throw new DataServiceFault(
                        "The given XSLT resource path at '" + path + "' does not exist");
            }
        } catch (RegistryException e) {
            String msg = "Error in retrieving the resource: " + path;
            throw new DataServiceFault(e, msg);
        }
    } else {
        File csvFile = new File(path);
        if (path.startsWith("." + File.separator) || path.startsWith(".." + File.separator)) {
            /* this is a relative path */
            path = csvFile.getAbsolutePath();
        }
        /* local file */
        ins = new FileInputStream(path);
    }
    return ins;
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:62,代码来源:DBUtils.java

示例11: getInputStreamFromPath

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
 * Creates and returns an InputStream from the file path / http location given.
 *
 * @throws IOException, SQLException
 * @see java.io.InputStream
 */
public static InputStream getInputStreamFromPath(String path) throws IOException, SQLException {
    InputStream ins;
    if (path.startsWith("http://")) {
        /* This is a url file path */
        /*
            Security Comment :
            This file path is trustworthy, this path is configured in the dbs file.
        */
        URL url = new URL(path);
        ins = url.openStream();
    } else if (isRegistryPath(path)) {
        try {
            RegistryService registryService = SQLDriverDSComponent.getRegistryService();
            if (registryService == null) {
                throw new SQLException("DBUtils.getInputStreamFromPath(): Registry service is not available");
            }
            Registry registry;
            if (path.startsWith(CONF_REGISTRY_PATH_PREFIX)) {
                if (path.length() > CONF_REGISTRY_PATH_PREFIX.length()) {
                    path = path.substring(CONF_REGISTRY_PATH_PREFIX.length());
                    registry = registryService.getConfigSystemRegistry(getCurrentTenantId());
                } else {
                    throw new SQLException("Empty configuration registry path given");
                }
            } else {
                if (path.length() > GOV_REGISTRY_PATH_PREFIX.length()) {
                    path = path.substring(GOV_REGISTRY_PATH_PREFIX.length());
                    registry = registryService.getGovernanceSystemRegistry(getCurrentTenantId());
                } else {
                    throw new SQLException("Empty governance registry path given");
                }
            }
            if (registry.resourceExists(path)) {
                Resource serviceResource = registry.get(path);
                ins = serviceResource.getContentStream();
            } else {
                throw new SQLException(
                        "The given XSLT resource path at '" + path + "' does not exist");
            }
        } catch (RegistryException e) {
            throw new SQLException(e);
        }
    } else {
        File file = new File(path);
        if (path.startsWith("." + File.separator) || path.startsWith(".." + File.separator)) {
            /* this is a relative path */
            path = file.getAbsolutePath();
        }
        /* local file */
        ins = new FileInputStream(path);
    }
    return ins;
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:60,代码来源:TDriverUtil.java

示例12: loadPolicy

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException, XMLStreamException {

        InputStream in = resource.getContentStream();
        XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
        StAXOMBuilder builder = new StAXOMBuilder(parser);

        OMElement policyElement = builder.getDocumentElement();
        return PolicyEngine.getPolicy(policyElement);

    }
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:11,代码来源:SecurityDeploymentInterceptor.java


注:本文中的org.wso2.carbon.registry.core.Resource.getContentStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。