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


Java DelimitedLineTokenizer类代码示例

本文整理汇总了Java中org.springframework.batch.item.file.transform.DelimitedLineTokenizer的典型用法代码示例。如果您正苦于以下问题:Java DelimitedLineTokenizer类的具体用法?Java DelimitedLineTokenizer怎么用?Java DelimitedLineTokenizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DelimitedLineTokenizer类属于org.springframework.batch.item.file.transform包,在下文中一共展示了DelimitedLineTokenizer类的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;
    }
 
开发者ID:create1st,项目名称:spring-batch,代码行数:20,代码来源:TicketReaderFactory.java

示例2: orderReader

import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入依赖的package包/类
@Bean
@StepScope
protected OrderImportItemReader orderReader(@Value("#{jobParameters['resource']}") final Resource orderCsvResource) {

    FlatFileItemReader flatFileItemReader = new FlatFileItemReader<>();
    flatFileItemReader.setLineMapper(new DefaultLineMapper<OrderCsvLineValue>() {{
        setLineTokenizer(new DelimitedLineTokenizer() {{
            setNames(ORDER_CSV_HEADER_NAMES);

        }});
        setFieldSetMapper(new BeanWrapperFieldSetMapper<OrderCsvLineValue>() {{
            setTargetType(OrderCsvLineValue.class);
        }});
    }});
    flatFileItemReader.setLinesToSkip(1);
    flatFileItemReader.setResource(orderCsvResource);

    SingleItemPeekableItemReader singleItemPeekableItemReader = new SingleItemPeekableItemReader();
    singleItemPeekableItemReader.setDelegate(flatFileItemReader);

    OrderImportItemReader reader = new OrderImportItemReader();
    reader.setDelegate(singleItemPeekableItemReader);

    return reader;
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-data,代码行数:26,代码来源:OrdersImportJobConfiguration.java

示例3: test

import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入依赖的package包/类
@Test
public void test() throws Exception {
    final String line = "11111111;111111-1034;19000101;;;Meikäläinen;Matti Esko;fi;fi;[email protected];123;123;" +
            "20160101;20170101;2016;2017;20160801;20170731;19900101;20200101;;;Kadunnimi 123;01110;Kaupunki;" +
            "FI;Suomi;1;1;1;12345678901;12345678902;2017;2016";

    final DefaultLineMapper<InnofactorImportFileLine> lineMapper = new DefaultLineMapper<>();
    lineMapper.setFieldSetMapper(new InnofactorImportFileFieldSetMapper());
    lineMapper.setLineTokenizer(new DelimitedLineTokenizer(";"));

    final InnofactorImportFileLine res = lineMapper.mapLine(line, 0);
    final InnofactorImportFormatter formatter = new InnofactorImportFormatter();
    final MetsastajaRekisteriPerson person = formatter.process(res);
    final MetsastajaRekisteriItemValidator validator = new MetsastajaRekisteriItemValidator();
    validator.process(person);
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:17,代码来源:InnofactorImportFileFieldSetMapperTest.java

示例4: flatFileItemReader

import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入依赖的package包/类
@Bean
@StepScope
FlatFileItemReader<Person> flatFileItemReader(@Value("#{jobParameters[file]}") File file) {
    FlatFileItemReader<Person> r = new FlatFileItemReader<>();
    r.setResource(new FileSystemResource(file));
    r.setLineMapper(new DefaultLineMapper<Person>() {
        {
            this.setLineTokenizer(new DelimitedLineTokenizer(",") {
                {
                    this.setNames(new String[]{"first", "last", "email"});
                }
            });
            this.setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {
                {
                    this.setTargetType(Person.class);
                }
            });
        }
    });
    return r;
}
 
开发者ID:livelessons-spring,项目名称:building-microservices,代码行数:22,代码来源:BatchConfiguration.java

示例5: 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());
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:22,代码来源:BOMIgnoringFlatFileItemReaderTest.java

示例6: 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;
}
 
开发者ID:subes,项目名称:invesdwin-nowicket,代码行数:23,代码来源:CsvItemReaderBuilder.java

示例7: fillPreviewLines

import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入依赖的package包/类
protected void fillPreviewLines(MultipartFile file) {
    try {
        Resource resource = new InputStreamResource(new ByteArrayInputStream(file.getBytes()));
        DefaultLineMapper<String[]> lineMapper = new DefaultLineMapper<>();
        lineMapper.setLineTokenizer(new DelimitedLineTokenizer());
        lineMapper.setFieldSetMapper(FieldSet::getValues);

        FlatFileItemReader<String[]> itemReader = new FlatFileItemReader<>();
        itemReader.setResource(resource);
        itemReader.setLineMapper(lineMapper);
        itemReader.open(new ExecutionContext());

        for (int i = 0; i < 10; i++) {
            String[] row = itemReader.read();
            if (row == null) {
                break;
            }

            firstRows.add(row);
            columnCount = Math.max(columnCount, row.length);
        }

    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:imCodePartnerAB,项目名称:iVIS,代码行数:27,代码来源:FileOption.java

示例8: 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());
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:22,代码来源:BOMIgnoringFlatFileItemReaderTest.java

示例9: 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;
}
 
开发者ID:joshlong,项目名称:javaconfig-ftw,代码行数:29,代码来源:BatchConfiguration.java

示例10: 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;
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:25,代码来源:SkipConfiguration.java

示例11: 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;
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:54,代码来源:StoreInitializer.java

示例12: 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;
}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:41,代码来源:BatchReadApplicationsFromCsv.java

示例13: inputLineMapper

import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入依赖的package包/类
private static LineMapper<LHHuntingClubCSVRow> inputLineMapper() {
    DefaultLineMapper<LHHuntingClubCSVRow> lineMapper = new DefaultLineMapper<>();

    lineMapper.setFieldSetMapper(new LHHuntingClubLineFieldMapper());
    lineMapper.setLineTokenizer(new DelimitedLineTokenizer(";"));

    return lineMapper;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:9,代码来源:LHHuntingClubBatchConfig.java

示例14: innofactorImportLineMapper

import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //导入依赖的package包/类
private static LineMapper<InnofactorImportFileLine> innofactorImportLineMapper() {
    DefaultLineMapper<InnofactorImportFileLine> lineMapper = new DefaultLineMapper<>();

    lineMapper.setFieldSetMapper(new InnofactorImportFileFieldSetMapper());
    lineMapper.setLineTokenizer(new DelimitedLineTokenizer(";"));

    return lineMapper;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:9,代码来源:InnofactorImportConfig.java

示例15: 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();
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:43,代码来源:DescriptionParsingTest.java


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