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


Java EncodedResource.getReader方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: readScript

import org.springframework.core.io.support.EncodedResource; //导入方法依赖的package包/类
/**
 * Read a script from the provided resource, using the supplied comment prefix
 * and statement separator, and build a {@code String} containing the lines.
 * <p>Lines <em>beginning</em> with the comment prefix are excluded from the
 * results; however, line comments anywhere else &mdash; for example, within
 * a statement &mdash; will be included in the results.
 * @param resource the {@code EncodedResource} containing the script
 * to be processed
 * @param commentPrefix the prefix that identifies comments in the SQL script &mdash;
 * typically "--"
 * @param separator the statement separator in the SQL script &mdash; typically ";"
 * @return a {@code String} containing the script lines
 * @throws IOException in case of I/O errors
 */
private static String readScript(EncodedResource resource, String commentPrefix, String separator)
		throws IOException {
	LineNumberReader lnr = new LineNumberReader(resource.getReader());
	try {
		return readScript(lnr, commentPrefix, separator);
	}
	finally {
		lnr.close();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:ScriptUtils.java

示例5: readScript

import org.springframework.core.io.support.EncodedResource; //导入方法依赖的package包/类
/**
 * Read a script from the provided resource, using the supplied comment prefix
 * and statement separator, and build a {@code String} containing the lines.
 * <p>Lines <em>beginning</em> with the comment prefix are excluded from the
 * results; however, line comments anywhere else &mdash; for example, within
 * a statement &mdash; will be included in the results.
 * @param resource the {@code EncodedResource} containing the script
 * to be processed
 * @param commentPrefix the prefix that identifies comments in the SQL script &mdash;
 * typically "--"
 * @param separator the statement separator in the SQL script &mdash; typically ";"
 * @return a {@code String} containing the script lines
 * @throws IOException in case of I/O errors
 */
private static String readScript(EncodedResource resource, String commentPrefix, String separator)
		throws IOException {

	LineNumberReader lnr = new LineNumberReader(resource.getReader());
	try {
		return readScript(lnr, commentPrefix, separator);
	}
	finally {
		lnr.close();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:ScriptUtils.java

示例6: readScript

import org.springframework.core.io.support.EncodedResource; //导入方法依赖的package包/类
/**
 * Read a script from the provided resource, using the supplied comment prefix
 * and statement separator, and build a {@code String} containing the lines.
 * <p>Lines <em>beginning</em> with the comment prefix are excluded from the
 * results; however, line comments anywhere else &mdash; for example, within
 * a statement &mdash; will be included in the results.
 *
 * @param resource      the {@code EncodedResource} containing the script
 *                      to be processed
 * @param commentPrefix the prefix that identifies comments in the SQL script &mdash;
 *                      typically "--"
 * @param separator     the statement separator in the SQL script &mdash; typically ";"
 * @return a {@code String} containing the script lines
 * @throws IOException in case of I/O errors
 */
private static String readScript(EncodedResource resource, String commentPrefix, String separator)
        throws IOException {
    LineNumberReader lnr = new LineNumberReader(resource.getReader());
    try {
        return readScript(lnr, commentPrefix, separator);
    } finally {
        lnr.close();
    }
}
 
开发者ID:davyvanroy,项目名称:spring-sql-unit,代码行数:25,代码来源:ScriptUtils.java


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