當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。