本文整理汇总了Java中org.springframework.batch.item.file.transform.DelimitedLineTokenizer.setNames方法的典型用法代码示例。如果您正苦于以下问题:Java DelimitedLineTokenizer.setNames方法的具体用法?Java DelimitedLineTokenizer.setNames怎么用?Java DelimitedLineTokenizer.setNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.batch.item.file.transform.DelimitedLineTokenizer
的用法示例。
在下文中一共展示了DelimitedLineTokenizer.setNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createReader
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
public ItemStreamReader<Ticket> createReader(final Resource source) {
final FlatFileItemReader<Ticket> reader = new FlatFileItemReader<>();
reader.setResource(source);
final DefaultLineMapper<Ticket> lineMapper = new DefaultLineMapper<>();
final DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
lineTokenizer.setNames(TICKET_FILE_CSV_FIELDS);
lineMapper.setLineTokenizer(lineTokenizer);
final BeanWrapperFieldSetMapper<Ticket> fieldMapper = new BeanWrapperFieldSetMapper<>();
fieldMapper.setTargetType(Ticket.class);
final DateFormat df = new SimpleDateFormat(DATE_FORMAT);
final Map<Class, PropertyEditor> customEditors = Stream.of(
new AbstractMap.SimpleEntry<>(Date.class, new CustomDateEditor(df, false)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
fieldMapper.setCustomEditors(customEditors);
lineMapper.setFieldSetMapper(fieldMapper);
reader.setLineMapper(lineMapper);
return reader;
}
示例2: 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());
}
示例3: 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;
}
示例4: 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());
}
示例5: reader
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
/**
* maps CSV data into rows of fields, which are then
* mapped to Customer.class instances based on conventions:
* <p/>
* <CODE>col 1 => firstName => customer.setFirstName(String)</CODE>
*/
@Bean(name = readCsvFileIntoTableStepReader)
@StepScope
public FlatFileItemReader<Customer> reader(@Value("#{jobParameters['input.file']}") Resource resource) throws Exception {
log.debug(String.format("building FlatFileItemReader to read in the file %s", resource.getFile().getAbsolutePath()));
FlatFileItemReader<Customer> csvFileReader = new FlatFileItemReader<Customer>();
csvFileReader.setResource(resource);
DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer(DelimitedLineTokenizer.DELIMITER_COMMA);
delimitedLineTokenizer.setNames(new String[]{"lastName", "firstName"});
BeanWrapperFieldSetMapper<Customer> beanWrapperFieldSetMapper = new BeanWrapperFieldSetMapper<Customer>();
beanWrapperFieldSetMapper.setTargetType(Customer.class);
DefaultLineMapper<Customer> defaultLineMapper = new DefaultLineMapper<Customer>();
defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
defaultLineMapper.setFieldSetMapper(beanWrapperFieldSetMapper);
csvFileReader.setLineMapper(defaultLineMapper);
return csvFileReader;
}
示例6: productReader
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
@Bean
@StepScope
public FlatFileItemReader<Product> productReader(@Value("#{jobParameters['inputFile']}") String inputFile) {
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(",");
tokenizer.setNames(new String[] { "PRODUCT_ID", "NAME", "DESCRIPTION", "PRICE" });
DefaultLineMapper<Product> lineMapper = new DefaultLineMapper<Product>();
lineMapper.setLineTokenizer(tokenizer);
lineMapper.setFieldSetMapper(new ProductFieldSetMapper());
FlatFileItemReader<Product> reader = new FlatFileItemReader<Product>();
try {
reader.setResource(new FileSystemResource(ResourceUtils.getFile(inputFile)));
} catch (FileNotFoundException e) {
log.error("파일을 찾을 수 없습니다. inputFile=" + inputFile, e);
throw new RuntimeException(e);
}
reader.setLinesToSkip(1);
reader.setLineMapper(lineMapper);
return reader;
}
示例7: 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;
}
示例8: getLineMapper
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
private DefaultLineMapper<Application> getLineMapper() {
DefaultLineMapper<Application> mapper = new DefaultLineMapper<>();
DelimitedLineTokenizer delimiter = new DelimitedLineTokenizer();
// counter for Application#id
final AtomicInteger counter = new AtomicInteger(1);
// define the name of each line token
delimiter.setNames(new String[] { "name", "environment", "url", "authScheme", "actuatorUsername", "actuatorPassword" });
mapper.setLineTokenizer(delimiter);
// For each line
mapper.setFieldSetMapper(line -> {
AuthScheme authScheme = AuthScheme.parse(line.readString("authScheme"));
Application app;
if(authScheme == AuthScheme.BASIC) {
app = new Application(
counter.getAndIncrement(),
line.readString("name"),
line.readString("environment"),
line.readString("url"),
line.readString("actuatorUsername"),
line.readString("actuatorPassword"));
} else {
app = new Application(
counter.getAndIncrement(),
line.readString("name"),
line.readString("environment"),
line.readString("url"));
}
LOGGER.info("Loaded {}", app);
return app;
});
return mapper;
}
示例9: setUp
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
/**
*
*/
@Before
public final void setUp() throws Exception {
String[] names = new String[] {
"http://rs.tdwg.org/dwc/terms/taxonID",
"http://purl.org/dc/terms/type",
"http://purl.org/dc/elements/1.1/source",
"http://purl.org/dc/terms/modified",
"http://purl.org/dc/terms/create",
"http://purl.org/dc/terms/creator",
"http://purl.org/dc/terms/description",
"http://purl.org/dc/terms/references",
"http://purl.org/dc/terms/source"
};
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
tokenizer.setDelimiter('\t');
tokenizer.setNames(names);
taxonService = EasyMock.createMock(TaxonService.class);
conversionService = EasyMock.createMock(ConversionService.class);
FieldSetMapper fieldSetMapper = new FieldSetMapper();
fieldSetMapper.setConversionService(conversionService);
HtmlSanitizer htmlSanitizer = new HtmlSanitizer();
htmlSanitizer.afterPropertiesSet();
fieldSetMapper.setHtmlSanitizer(htmlSanitizer);
fieldSetMapper.setFieldNames(names);
fieldSetMapper.setDefaultValues(new HashMap<String, String>());
fieldSetMapper.setTaxonService(taxonService);
DefaultLineMapper<Description> lineMapper
= new DefaultLineMapper<Description>();
lineMapper.setFieldSetMapper(fieldSetMapper);
lineMapper.setLineTokenizer(tokenizer);
flatFileItemReader.setEncoding("UTF-8");
flatFileItemReader.setLinesToSkip(0);
flatFileItemReader.setResource(content);
flatFileItemReader.setLineMapper(lineMapper);
flatFileItemReader.afterPropertiesSet();
}
示例10: setUp
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
@Before
public final void setUp() throws Exception {
String[] names = new String[] {
"http://rs.tdwg.org/dwc/terms/taxonID",
"http://purl.org/dc/terms/type",
"http://purl.org/dc/elements/1.1/source",
"http://purl.org/dc/terms/modified",
"http://purl.org/dc/terms/create",
"http://purl.org/dc/terms/creator",
"http://purl.org/dc/terms/description",
"http://purl.org/dc/terms/references",
"http://purl.org/dc/terms/source"
};
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
tokenizer.setDelimiter(DelimitedLineTokenizer.DELIMITER_TAB);
tokenizer.setNames(names);
taxonService = createMock(TaxonService.class);
conversionService = createMock(ConversionService.class);
FieldSetMapper fieldSetMapper = new FieldSetMapper();
fieldSetMapper.setConversionService(conversionService);
fieldSetMapper.setFieldNames(names);
fieldSetMapper.setDefaultValues(new HashMap<String, String>());
fieldSetMapper.setTaxonService(taxonService);
DefaultLineMapper<Description> lineMapper = new DefaultLineMapper<Description>();
lineMapper.setFieldSetMapper(fieldSetMapper);
lineMapper.setLineTokenizer(tokenizer);
flatFileItemReader.setEncoding("UTF-8");
flatFileItemReader.setLinesToSkip(0);
flatFileItemReader.setResource(content);
flatFileItemReader.setLineMapper(lineMapper);
flatFileItemReader.afterPropertiesSet();
}
示例11: lineMapper
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
@Bean
@StepScope
public DefaultLineMapper<Product> lineMapper() {
DefaultLineMapper<Product> mapper = new DefaultLineMapper<Product>();
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
tokenizer.setNames(FIELD_NAMES);
mapper.setLineTokenizer(tokenizer);
ProductFieldSetMapper fieldSetMapper = new ProductFieldSetMapper();
mapper.setFieldSetMapper(fieldSetMapper);
return mapper;
}
示例12: setUp
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
@Before
public final void setUp() throws Exception {
String[] names = new String[] {
"http://rs.tdwg.org/dwc/terms/taxonID",
"http://rs.tdwg.org/dwc/terms/scientificName",
"http://rs.tdwg.org/dwc/terms/scientificNameID",
"http://rs.tdwg.org/dwc/terms/scientificNameAuthorship",
"http://rs.tdwg.org/dwc/terms/taxonRank",
"http://rs.tdwg.org/dwc/terms/taxonomicStatus",
"http://rs.tdwg.org/dwc/terms/parentNameUsageID",
"http://rs.tdwg.org/dwc/terms/acceptedNameUsageID",
"http://rs.tdwg.org/dwc/terms/genus",
"http://rs.tdwg.org/dwc/terms/subgenus",
"http://rs.tdwg.org/dwc/terms/specificEpithet",
"http://rs.tdwg.org/dwc/terms/infraspecificEpithet",
"http://rs.tdwg.org/dwc/terms/nomenclaturalStatus",
"http://purl.org/dc/terms/modified",
"http://purl.org/dc/terms/source"
};
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
tokenizer.setDelimiter('\t');
tokenizer.setNames(names);
taxonService = EasyMock.createMock(TaxonService.class);
Set<Converter> converters = new HashSet<Converter>();
converters.add(new StringToIsoDateTimeConverter());
converters.add(new TaxonomicStatusConverter());
converters.add(new RankConverter());
converters.add(new NomenclaturalStatusConverter());
ConversionServiceFactoryBean factoryBean = new ConversionServiceFactoryBean();
factoryBean.setConverters(converters);
factoryBean.afterPropertiesSet();
ConversionService conversionService = factoryBean.getObject();
FieldSetMapper fieldSetMapper = new FieldSetMapper();
fieldSetMapper.setFieldNames(names);
fieldSetMapper.setDefaultValues(new HashMap<String, String>());
fieldSetMapper.setConversionService(conversionService);
DefaultLineMapper<Taxon> lineMapper
= new DefaultLineMapper<Taxon>();
lineMapper.setFieldSetMapper(fieldSetMapper);
lineMapper.setLineTokenizer(tokenizer);
flatFileItemReader.setEncoding("UTF-8");
flatFileItemReader.setLinesToSkip(0);
flatFileItemReader.setResource(content);
flatFileItemReader.setLineMapper(lineMapper);
flatFileItemReader.afterPropertiesSet();
}
示例13: setUp
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
/**
*
*/
@Before
public final void setUp() throws Exception {
String[] names = new String[] {
"http://rs.tdwg.org/dwc/terms/taxonID",
"http://rs.tdwg.org/dwc/terms/scientificName",
"http://rs.tdwg.org/dwc/terms/vernacularName",
"http://rs.tdwg.org/dwc/terms/taxonomicStatus",
"http://rs.tdwg.org/dwc/terms/taxonRank",
"http://rs.tdwg.org/dwc/terms/scientificNameAuthorship",
"http://purl.org/dc/terms/bibliographicCitation",
"http://rs.tdwg.org/dwc/terms/parentNameUsageID"
};
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
tokenizer.setDelimiter(',');
tokenizer.setQuoteCharacter('\"');
tokenizer.setNames(names);
Set<Converter> converters = new HashSet<Converter>();
converters.add(new TaxonomicStatusConverter());
converters.add(new RankConverter());
ConversionServiceFactoryBean factoryBean = new ConversionServiceFactoryBean();
factoryBean.setConverters(converters);
factoryBean.afterPropertiesSet();
ConversionService conversionService = factoryBean.getObject();
taxonService = EasyMock.createMock(TaxonService.class);
FieldSetMapper fieldSetMapper = new FieldSetMapper();
fieldSetMapper.setConversionService(conversionService);
fieldSetMapper.setFieldNames(names);
fieldSetMapper.setDefaultValues(new HashMap<String, String>());
DefaultLineMapper<Taxon> lineMapper
= new DefaultLineMapper<Taxon>();
lineMapper.setFieldSetMapper(fieldSetMapper);
lineMapper.setLineTokenizer(tokenizer);
flatFileItemReader.setEncoding("UTF-8");
flatFileItemReader.setLinesToSkip(0);
flatFileItemReader.setResource(content);
flatFileItemReader.setLineMapper(lineMapper);
flatFileItemReader.afterPropertiesSet();
}
示例14: setUp
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
/**
* @throws Exception if there is a problem
*/
@Before
public final void setUp() throws Exception {
String[] names = new String[] {
"http://rs.tdwg.org/dwc/terms/taxonID",
"http://purl.org/dc/terms/modified",
"http://purl.org/dc/terms/created",
"http://purl.org/dc/terms/identifier",
"http://purl.org/dc/terms/bibliographicCitation",
"http://purl.org/dc/terms/type",
"http://purl.org/dc/terms/title",
"http://purl.org/ontology/bibo/volume",
"http://purl.org/ontology/bibo/number",
"http://purl.org/ontology/bibo/pages",
"http://purl.org/dc/terms/description",
"http://purl.org/dc/terms/date",
"http://purl.org/dc/terms/source",
"http://purl.org/dc/terms/creator"
};
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
tokenizer.setDelimiter('\t');
tokenizer.setNames(names);
Set<Converter> converters = new HashSet<Converter>();
converters.add(new ReferenceTypeConverter());
converters.add(new StringToIsoDateTimeConverter());
ConversionServiceFactoryBean factoryBean = new ConversionServiceFactoryBean();
factoryBean.setConverters(converters);
factoryBean.afterPropertiesSet();
ConversionService conversionService = factoryBean.getObject();
taxonService = EasyMock.createMock(TaxonService.class);
FieldSetMapper fieldSetMapper = new FieldSetMapper();
HtmlSanitizer htmlSanitizer = new HtmlSanitizer();
htmlSanitizer.afterPropertiesSet();
fieldSetMapper.setHtmlSanitizer(htmlSanitizer);
fieldSetMapper.setFieldNames(names);
fieldSetMapper.setConversionService(conversionService);
fieldSetMapper.setDefaultValues(new HashMap<String, String>());
fieldSetMapper.setTaxonService(taxonService);
DefaultLineMapper<Reference> lineMapper
= new DefaultLineMapper<Reference>();
lineMapper.setFieldSetMapper(fieldSetMapper);
lineMapper.setLineTokenizer(tokenizer);
flatFileItemReader.setEncoding("UTF-8");
flatFileItemReader.setLinesToSkip(0);
flatFileItemReader.setResource(content);
flatFileItemReader.setLineMapper(lineMapper);
flatFileItemReader.afterPropertiesSet();
}
示例15: setUp
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入方法依赖的package包/类
/**
* @throws Exception if there is a problem
*/
@Before
public final void setUp() throws Exception {
String[] names = new String[] {
"http://rs.tdwg.org/dwc/terms/taxonID",
"http://purl.org/dc/terms/identifier",
"",
"http://purl.org/ontology/bibo/doi",
"http://purl.org/ontology/bibo/isbn",
"http://purl.org/ontology/bibo/issn",
"",
"",
"http://purl.org/dc/terms/bibliographicCitation",
"http://purl.org/dc/terms/title",
"http://purl.org/dc/terms/creator",
"http://purl.org/dc/terms/source",
"http://purl.org/dc/terms/description",
"http://purl.org/dc/terms/subject",
"http://purl.org/dc/terms/language",
"http://purl.org/dc/terms/type",
"http://purl.org/dc/terms/date",
"http://purl.org/dc/terms/created",
"http://purl.org/dc/terms/modified"
};
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
tokenizer.setDelimiter(',');
tokenizer.setQuoteCharacter('"');
tokenizer.setNames(names);
taxonService = EasyMock.createMock(TaxonService.class);
Set<Converter> converters = new HashSet<Converter>();
converters.add(new ReferenceTypeConverter());
converters.add(new StringToIsoDateTimeConverter());
ConversionServiceFactoryBean factoryBean = new ConversionServiceFactoryBean();
factoryBean.setConverters(converters);
factoryBean.afterPropertiesSet();
ConversionService conversionService = factoryBean.getObject();
FieldSetMapper fieldSetMapper = new FieldSetMapper();
HtmlSanitizer htmlSanitizer = new HtmlSanitizer();
htmlSanitizer.afterPropertiesSet();
fieldSetMapper.setHtmlSanitizer(htmlSanitizer);
fieldSetMapper.setConversionService(conversionService);
fieldSetMapper.setFieldNames(names);
fieldSetMapper.setDefaultValues(new HashMap<String, String>());
fieldSetMapper.setTaxonService(taxonService);
DefaultLineMapper<Reference> lineMapper
= new DefaultLineMapper<Reference>();
lineMapper.setFieldSetMapper(fieldSetMapper);
lineMapper.setLineTokenizer(tokenizer);
flatFileItemReader.setEncoding("UTF-8");
flatFileItemReader.setLinesToSkip(0);
flatFileItemReader.setResource(content);
flatFileItemReader.setLineMapper(lineMapper);
flatFileItemReader.afterPropertiesSet();
}