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


Java ClassPathResource.getInputStream方法代码示例

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


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

示例1: writeResourceToNetworkFile

import org.springframework.core.io.ClassPathResource; //导入方法依赖的package包/类
/**
 * Write the resource to the specified NetworkFile
 * @param resource
 * @param file
 * @throws IOException
 */
private void writeResourceToNetworkFile(ClassPathResource resource, NetworkFile file) throws IOException
{
 
    byte[] buffer= new byte[1000];
    InputStream is = resource.getInputStream();
    try
    {
        long offset = 0;
        int i = is.read(buffer, 0, buffer.length);
        while(i > 0)
        {
            file.writeFile(buffer, i, 0, offset);
            offset += i;
            i = is.read(buffer, 0, buffer.length);
        }                 
    }
    finally
    {
        is.close();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:28,代码来源:ContentDiskDriverTest.java

示例2: initDirectoryServer

import org.springframework.core.io.ClassPathResource; //导入方法依赖的package包/类
public static void initDirectoryServer(final InputStream ldifFile) throws IOException {
    final ClassPathResource properties = new ClassPathResource("ldap.properties");
    final ClassPathResource schema = new ClassPathResource("schema/standard-ldap.schema");

    DIRECTORY = new InMemoryTestLdapDirectoryServer(properties.getInputStream(),
            ldifFile,
            schema.getInputStream());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:9,代码来源:AbstractLdapTests.java

示例3: initDirectoryServer

import org.springframework.core.io.ClassPathResource; //导入方法依赖的package包/类
public static synchronized void initDirectoryServer(final InputStream ldifFile) throws IOException {
    try {
        final boolean createInstance = DIRECTORY == null || !DIRECTORY.isAlive();
        if (createInstance) {
            final ClassPathResource properties = new ClassPathResource("ldap.properties");
            final ClassPathResource schema = new ClassPathResource("schema/standard-ldap.schema");
            DIRECTORY = new InMemoryTestLdapDirectoryServer(properties.getInputStream(), ldifFile, schema.getInputStream());
        }
    } catch (final Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:13,代码来源:AbstractLdapTests.java

示例4: RubriekMap

import org.springframework.core.io.ClassPathResource; //导入方法依赖的package包/类
RubriekMap() {
    final ClassPathResource classPathResource = new ClassPathResource("rubriekmap.csv");
    try {
        try (InputStream is = classPathResource.getInputStream()) {
            parseStream(is);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:11,代码来源:RubriekMap.java

示例5: RubriekMap

import org.springframework.core.io.ClassPathResource; //导入方法依赖的package包/类
private RubriekMap() {
    final ClassPathResource classPathResource = new ClassPathResource("rubriekmap.csv");
    try {
        try (InputStream is = classPathResource.getInputStream()) {
            parseStream(is);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:11,代码来源:RubriekMap.java

示例6: readStores

import org.springframework.core.io.ClassPathResource; //导入方法依赖的package包/类
/**
 * Reads a file {@code starbucks.csv} from the class path and parses it into {@link Store} instances about to
 * persisted.
 * 
 * @return
 * @throws Exception
 */
public static List<Store> readStores() throws Exception {

	ClassPathResource resource = new ClassPathResource("starbucks.csv");
	Scanner scanner = new Scanner(resource.getInputStream());
	String line = scanner.nextLine();
	scanner.close();

	FlatFileItemReader<Store> itemReader = new FlatFileItemReader<Store>();
	itemReader.setResource(resource);

	// DelimitedLineTokenizer defaults to comma as its delimiter
	DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
	tokenizer.setNames(line.split(","));
	tokenizer.setStrict(false);

	DefaultLineMapper<Store> lineMapper = new DefaultLineMapper<Store>();
	lineMapper.setFieldSetMapper(fields -> {

		Point location = new Point(fields.readDouble("Longitude"), fields.readDouble("Latitude"));
		Address address = new Address(fields.readString("Street Address"), fields.readString("City"),
				fields.readString("Zip"), location);

		return new Store(fields.readString("Name"), address);
	});

	lineMapper.setLineTokenizer(tokenizer);
	itemReader.setLineMapper(lineMapper);
	itemReader.setRecordSeparatorPolicy(new DefaultRecordSeparatorPolicy());
	itemReader.setLinesToSkip(1);
	itemReader.open(new ExecutionContext());

	List<Store> stores = new ArrayList<>();
	Store store = null;

	do {

		store = itemReader.read();

		if (store != null) {
			stores.add(store);
		}

	} while (store != null);

	return stores;
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:54,代码来源:StoreInitializer.java

示例7: getJsFile

import org.springframework.core.io.ClassPathResource; //导入方法依赖的package包/类
private static InputStreamReader getJsFile(String fileName) throws IOException {
	ClassPathResource resource = new ClassPathResource("/" + fileName);
	return new InputStreamReader(resource.getInputStream());
	//resource.getInputStream()
	//byte[] data = CommonUtil.inputStreamToByteArray(resource.getInputStream());
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:7,代码来源:FieldCalculation.java


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