本文整理汇总了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();
}
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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());
}