本文整理汇总了Java中org.springframework.batch.item.file.transform.DelimitedLineTokenizer.setStrict方法的典型用法代码示例。如果您正苦于以下问题:Java DelimitedLineTokenizer.setStrict方法的具体用法?Java DelimitedLineTokenizer.setStrict怎么用?Java DelimitedLineTokenizer.setStrict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.batch.item.file.transform.DelimitedLineTokenizer
的用法示例。
在下文中一共展示了DelimitedLineTokenizer.setStrict方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
lineTokenizer.setDelimiter('\t');
lineTokenizer.setNames(new String[] {"foo","bar"});
lineTokenizer.setStrict(false);
DefaultLineMapper<FieldSet> lineMapper = new DefaultLineMapper<FieldSet>();
lineMapper.setLineTokenizer(lineTokenizer);
lineMapper.setFieldSetMapper(new PassThroughFieldSetMapper());
flatFileItemReader = new FlatFileItemReader<FieldSet>();
flatFileItemReader.setEncoding("UTF-8");
flatFileItemReader.setLinesToSkip(0);
flatFileItemReader.setLineMapper(lineMapper);
flatFileItemReader.setResource(new ClassPathResource("org/emonocot/bom.txt"));
flatFileItemReader.setBufferedReaderFactory(new BOMIgnoringBufferedReaderFactory());
flatFileItemReader.afterPropertiesSet();
flatFileItemReader.open(new ExecutionContext());
}
示例2: newDefaultLineMapper
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
private DefaultLineMapper<T> newDefaultLineMapper() {
final DefaultLineMapper<T> lineMapper = new DefaultLineMapper<T>();
final DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
if (delimiter != null) {
tokenizer.setDelimiter(delimiter);
}
if (names != null) {
tokenizer.setNames(names);
}
if (strict != null) {
tokenizer.setStrict(strict);
}
if (fieldSetFactory != null) {
tokenizer.setFieldSetFactory(fieldSetFactory);
}
lineMapper.setLineTokenizer(tokenizer);
if (fieldSetMapper != null) {
lineMapper.setFieldSetMapper(fieldSetMapper);
}
lineMapper.afterPropertiesSet();
return lineMapper;
}
示例3: setUp
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
lineTokenizer.setDelimiter(DelimitedLineTokenizer.DELIMITER_TAB);
lineTokenizer.setNames(new String[] {"foo","bar"});
lineTokenizer.setStrict(false);
DefaultLineMapper<FieldSet> lineMapper = new DefaultLineMapper<FieldSet>();
lineMapper.setLineTokenizer(lineTokenizer);
lineMapper.setFieldSetMapper(new PassThroughFieldSetMapper());
flatFileItemReader = new FlatFileItemReader<FieldSet>();
flatFileItemReader.setEncoding("UTF-8");
flatFileItemReader.setLinesToSkip(0);
flatFileItemReader.setLineMapper(lineMapper);
flatFileItemReader.setResource(new ClassPathResource("org/emonocot/bom.txt"));
flatFileItemReader.setBufferedReaderFactory(new BOMIgnoringBufferedReaderFactory());
flatFileItemReader.afterPropertiesSet();
flatFileItemReader.open(new ExecutionContext());
}
示例4: readStores
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的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;
}