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


Java EncodedResource类代码示例

本文整理汇总了Java中org.springframework.core.io.support.EncodedResource的典型用法代码示例。如果您正苦于以下问题:Java EncodedResource类的具体用法?Java EncodedResource怎么用?Java EncodedResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EncodedResource类属于org.springframework.core.io.support包,在下文中一共展示了EncodedResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initializeJiraDataBaseForSla

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
/**
 * Initialize data base with 'MDA' JIRA project.
 */
@BeforeClass
public static void initializeJiraDataBaseForSla() throws SQLException {
	final DataSource datasource = new SimpleDriverDataSource(new JDBCDriver(), "jdbc:hsqldb:mem:dataSource", null, null);
	final Connection connection = datasource.getConnection();
	try {
		ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/sla/jira-create.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/sla/jira.sql"), StandardCharsets.UTF_8));
	} finally {
		connection.close();
	}
}
 
开发者ID:ligoj,项目名称:plugin-bt-jira,代码行数:15,代码来源:JiraExportPluginResourceTest.java

示例2: loadProperties

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
protected void loadProperties(Properties props) throws IOException {
	if (this.locations != null) {
		for (Resource location : this.locations) {
			logger.info("Loading properties file from " + location);
			try {
				PropertiesLoaderUtils.fillProperties(props,
						new EncodedResource(location, this.fileEncoding));
			} catch (IOException ex) {
				if (this.ignoreResourceNotFound) {
					logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
				} else {
					throw ex;
				}
			}
		}
	}
}
 
开发者ID:penggle,项目名称:xproject,代码行数:18,代码来源:GlobalPropertySources.java

示例3: loadBeanDefinitions

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
/**
 * Load bean definitions from the specified properties file.
 * @param encodedResource the resource descriptor for the properties file,
 * allowing to specify an encoding to use for parsing the file
 * @param prefix a filter within the keys in the map: e.g. 'beans.'
 * (can be empty or {@code null})
 * @return the number of bean definitions found
 * @throws BeanDefinitionStoreException in case of loading or parsing errors
 */
public int loadBeanDefinitions(EncodedResource encodedResource, String prefix)
		throws BeanDefinitionStoreException {

	Properties props = new Properties();
	try {
		InputStream is = encodedResource.getResource().getInputStream();
		try {
			if (encodedResource.getEncoding() != null) {
				getPropertiesPersister().load(props, new InputStreamReader(is, encodedResource.getEncoding()));
			}
			else {
				getPropertiesPersister().load(props, is);
			}
		}
		finally {
			is.close();
		}
		return registerBeanDefinitions(props, prefix, encodedResource.getResource().getDescription());
	}
	catch (IOException ex) {
		throw new BeanDefinitionStoreException("Could not parse properties from " + encodedResource.getResource(), ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:PropertiesBeanDefinitionReader.java

示例4: initializeJiraDataBase

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
/**
 * Initialize data base with 'MDA' JIRA project.
 */
@BeforeClass
public static void initializeJiraDataBase() throws SQLException {
	datasource = new SimpleDriverDataSource(new JDBCDriver(), "jdbc:hsqldb:mem:dataSource", null, null);
	final Connection connection = datasource.getConnection();
	final JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
	try {
		ScriptUtils.executeSqlScript(connection,
				new EncodedResource(new ClassPathResource("sql/base-1/jira-create.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection,
				new EncodedResource(new ClassPathResource("sql/base-1/jira.sql"), StandardCharsets.UTF_8));
		jdbcTemplate.queryForList("SELECT * FROM pluginversion WHERE ID = 10075");
	} finally {
		connection.close();
	}
}
 
开发者ID:ligoj,项目名称:plugin-bt-jira,代码行数:19,代码来源:AbstractJiraTest.java

示例5: initializeJiraDataBaseForImport

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
/**
 * Initialize data base with 'MDA' JIRA project.
 */
@BeforeClass
public static void initializeJiraDataBaseForImport() throws SQLException {
	datasource = new SimpleDriverDataSource(new JDBCDriver(), "jdbc:hsqldb:mem:dataSource", null, null);
	final Connection connection = datasource.getConnection();
	try {
		ScriptUtils.executeSqlScript(connection,
				new EncodedResource(new ClassPathResource("sql/base-1/jira-create.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection,
				new EncodedResource(new ClassPathResource("sql/base-2/jira-create.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection,
				new EncodedResource(new ClassPathResource("sql/upload/jira-create.sql"), StandardCharsets.UTF_8));

		ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/base-1/jira.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/base-2/jira.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/upload/jira.sql"), StandardCharsets.UTF_8));
	} finally {
		connection.close();
	}
}
 
开发者ID:ligoj,项目名称:plugin-bt-jira,代码行数:23,代码来源:JiraUpdateDaoTest.java

示例6: getPropertiesFromFile

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
private Properties getPropertiesFromFile(String baseName, Resource resource) {
    Properties properties = new Properties();

    String fileType = FileUtils.getFileExt(resource.getFilename());

    try {
        if (SUFFIX_OF_PROPERTIES.equals(fileType)) {
            //1.properties
            PropertiesLoaderUtils.fillProperties(properties, new EncodedResource(resource, "UTF-8"));
        } else if (SUFFIX_OF_TEXT.equals(fileType) || SUFFIX_OF_HTML.equals(fileType)) {
            //2.txt/html
            properties.put(baseName, ResourceUtils.getContent(resource));
        } else {
            //do nothing!
            logger.debug("this file '{}' is not properties, txt, html!", resource);
        }
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }

    return properties;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:24,代码来源:ResourceBundleHolder.java

示例7: initExtResources

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
private static void initExtResources() {
    String filePath = System.getProperty(EXT_PARAMS_FILE_NAME);
    if (StringUtils.isBlank(filePath)) {
        return;
    }

    System.out.println(String.format("获取到%s路径为'{%s}'!", EXT_PARAMS_FILE_NAME, filePath));

    Resource resource = new FileSystemResource(filePath);
    if (!resource.exists()) {
        System.err.println(String.format("找不到外部文件'[%s]'!", filePath));
        return;
    }

    try {
        PropertiesLoaderUtils.fillProperties(EXT_PARAMS_PROPERTIES, new EncodedResource(resource, "UTF-8"));
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println(String.format("读取路径为'%s'的文件失败!失败原因是'%s'!", filePath, e.getMessage()));
    }
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:22,代码来源:ParamsHome.java

示例8: resourceInjection

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
@Test
public void resourceInjection() throws IOException {
	System.setProperty("logfile", "log4j.properties");
	try {
		AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ResourceInjectionBean.class);
		ResourceInjectionBean resourceInjectionBean = ac.getBean(ResourceInjectionBean.class);
		Resource resource = new ClassPathResource("log4j.properties");
		assertEquals(resource, resourceInjectionBean.resource);
		assertEquals(resource.getURL(), resourceInjectionBean.url);
		assertEquals(resource.getURI(), resourceInjectionBean.uri);
		assertEquals(resource.getFile(), resourceInjectionBean.file);
		assertArrayEquals(FileCopyUtils.copyToByteArray(resource.getInputStream()),
				FileCopyUtils.copyToByteArray(resourceInjectionBean.inputStream));
		assertEquals(FileCopyUtils.copyToString(new EncodedResource(resource).getReader()),
				FileCopyUtils.copyToString(resourceInjectionBean.reader));
	}
	finally {
		System.getProperties().remove("logfile");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:ApplicationContextExpressionTests.java

示例9: getProperties

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
/**
 * 获取指定的资源对象
 * @param propertiesFilePath
 * @return
 */
public static Properties getProperties(String propertiesFilePath){
	Properties properties = null;
	try {
		logger.info("加载资源[" + propertiesFilePath + "] ...");
		
		properties = PropertiesLoaderUtils.loadProperties(new EncodedResource(new ClassPathResource(propertiesFilePath), "UTF-8"));
	} 
	catch (IOException e) {
		logger.error("加载资源[" + propertiesFilePath + "]失败");
		logger.error(e.getMessage());

		e.printStackTrace();
	}
	
	return properties;
}
 
开发者ID:yinshipeng,项目名称:sosoapi-base,代码行数:22,代码来源:PropertiesUtils.java

示例10: build

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
protected void build() {
	for (Resource location : this.locations) {
		if (location == null) {
			continue;
		}
		try {
			Properties prop = PropertiesLoaderUtils.loadProperties(new EncodedResource(location,"UTF-8"));
			for (Entry<Object, Object> entry : prop.entrySet()) {
				ErrorCodeTool.setProperty(entry.getKey().toString(), entry.getValue().toString());
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:yinshipeng,项目名称:sosoapi-base,代码行数:17,代码来源:ErrorCodePropertyConfigurer.java

示例11: readScript

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
/**
 * Read a script from the given resource and build a String containing the lines.
 * @param resource the resource to be read
 * @return {@code String} containing the script lines
 * @throws IOException in case of I/O errors
 */
private String readScript(EncodedResource resource) throws IOException {
	LineNumberReader lnr = new LineNumberReader(resource.getReader());
	try {
		String currentStatement = lnr.readLine();
		StringBuilder scriptBuilder = new StringBuilder();
		while (currentStatement != null) {
			if (StringUtils.hasText(currentStatement) &&
					(this.commentPrefix != null && !currentStatement.startsWith(this.commentPrefix))) {
				if (scriptBuilder.length() > 0) {
					scriptBuilder.append('\n');
				}
				scriptBuilder.append(currentStatement);
			}
			currentStatement = lnr.readLine();
		}
		maybeAddSeparatorToScript(scriptBuilder);
		return scriptBuilder.toString();
	}
	finally {
		lnr.close();
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:29,代码来源:ResourceDatabasePopulator.java

示例12: readAndSplitScriptContainingComments

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
@Test
public void readAndSplitScriptContainingComments() throws Exception {

	EncodedResource resource = new EncodedResource(new ClassPathResource("test-data-with-comments.sql", getClass()));
	LineNumberReader lineNumberReader = new LineNumberReader(resource.getReader());

	String script = JdbcTestUtils.readScript(lineNumberReader);

	char delim = ';';
	List<String> statements = new ArrayList<String>();
	JdbcTestUtils.splitSqlScript(script, delim, statements);

	String statement1 = "insert into customer (id, name) values (1, 'Rod; Johnson'), (2, 'Adrian Collier')";
	String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)";
	String statement3 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)";
	// Statement 4 addresses the error described in SPR-9982.
	String statement4 = "INSERT INTO persons( person_id , name) VALUES( 1 , 'Name' )";

	assertEquals("wrong number of statements", 4, statements.size());
	assertEquals("statement 1 not split correctly", statement1, statements.get(0));
	assertEquals("statement 2 not split correctly", statement2, statements.get(1));
	assertEquals("statement 3 not split correctly", statement3, statements.get(2));
	assertEquals("statement 4 not split correctly", statement4, statements.get(3));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:25,代码来源:JdbcTestUtilsTests.java

示例13: toMailSender

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
private JavaMailSender toMailSender(Event event) {
    JavaMailSenderImpl r = new CustomJavaMailSenderImpl();
    r.setDefaultEncoding("UTF-8");

    r.setHost(configurationManager.getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_HOST)));
    r.setPort(Integer.valueOf(configurationManager.getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PORT))));
    r.setProtocol(configurationManager.getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PROTOCOL)));
    r.setUsername(configurationManager.getStringConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_USERNAME), null));
    r.setPassword(configurationManager.getStringConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PASSWORD), null));

    String properties = configurationManager.getStringConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PROPERTIES), null);

    if (properties != null) {
        try {
            Properties prop = PropertiesLoaderUtils.loadProperties(new EncodedResource(new ByteArrayResource(
                    properties.getBytes(StandardCharsets.UTF_8)), "UTF-8"));
            r.setJavaMailProperties(prop);
        } catch (IOException e) {
            log.warn("error while setting the mail sender properties", e);
        }
    }
    return r;
}
 
开发者ID:alfio-event,项目名称:alf.io,代码行数:24,代码来源:SmtpMailer.java

示例14: readScript

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
private static String readScript(Resource resource) throws IOException {
	EncodedResource encoded = resource instanceof EncodedResource ? (EncodedResource) resource : new EncodedResource(resource);
	LineNumberReader lnr = new LineNumberReader(encoded.getReader());
	String currentStatement = lnr.readLine();
	StringBuilder scriptBuilder = new StringBuilder();
	while (currentStatement != null) {
		if (StringUtils.hasText(currentStatement) && (SQL_COMMENT_PREFIX != null && !currentStatement.startsWith(SQL_COMMENT_PREFIX))) {
			if (scriptBuilder.length() > 0) {
				scriptBuilder.append('\n');
			}
			scriptBuilder.append(currentStatement);
		}
		currentStatement = lnr.readLine();
	}
	return scriptBuilder.toString();
}
 
开发者ID:mqprichard,项目名称:spring-greenhouse-clickstart,代码行数:17,代码来源:SqlDatabaseChange.java

示例15: loadBeanDefinitions

import org.springframework.core.io.support.EncodedResource; //导入依赖的package包/类
/**
 * Load bean definitions from the specified XML file.
 * @param encodedResource the resource descriptor for the XML file,
 * allowing to specify an encoding to use for parsing the file
 * @return the number of bean definitions found
 * @throws BeanDefinitionStoreException in case of loading or parsing errors
 */
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
	Assert.notNull(encodedResource, "EncodedResource must not be null");
	if (logger.isInfoEnabled()) {
		logger.info("Loading XML bean definitions from " + encodedResource.getResource());
	}

	Set<EncodedResource> currentResources = this.resourcesCurrentlyBeingLoaded.get();
	if (currentResources == null) {
		currentResources = new HashSet<EncodedResource>(4);
		this.resourcesCurrentlyBeingLoaded.set(currentResources);
	}
	if (!currentResources.add(encodedResource)) {
		throw new BeanDefinitionStoreException(
				"Detected cyclic loading of " + encodedResource + " - check your import definitions!");
	}
	try {
		InputStream inputStream = encodedResource.getResource().getInputStream();
		try {
			InputSource inputSource = new InputSource(inputStream);
			if (encodedResource.getEncoding() != null) {
				inputSource.setEncoding(encodedResource.getEncoding());
			}
			return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
		}
		finally {
			inputStream.close();
		}
	}
	catch (IOException ex) {
		throw new BeanDefinitionStoreException(
				"IOException parsing XML document from " + encodedResource.getResource(), ex);
	}
	finally {
		currentResources.remove(encodedResource);
		if (currentResources.isEmpty()) {
			this.resourcesCurrentlyBeingLoaded.remove();
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:XmlBeanDefinitionReader.java


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