• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FlatFileParseException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FlatFileParseException类属于org.springframework.batch.item.file包,在下文中一共展示了FlatFileParseException类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testCreateReaderAndFailToRead

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Test(expected = FlatFileParseException.class)
public void testCreateReaderAndFailToRead() throws Exception {
    // given
    final ExecutionContext executionContext = mock(ExecutionContext.class);

    // when
    final ItemStreamReader<Ticket> reader = factory.createReader(new ClassPathResource("tickets-fail.csv"));

    try {
        reader.open(executionContext);
        System.out.println(reader.read());
    } finally {
        reader.close();
    }

    // then
}
 
开发者ID:create1st,项目名称:spring-batch,代码行数:18,代码来源:TicketReaderFactoryTest.java


示例2: importProductsJob

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Bean
public Job importProductsJob(Tasklet decompressTasklet, ItemReader<Product> reader) {

    Step decompress = stepBuilders.get("decompress")
                                  .tasklet(decompressTasklet)
                                  .repository(jobRepository)
                                  .transactionManager(transactionManager)
                                  .build();

    Step readWriteProducts = stepBuilders.get("readWriteProducts")
                                         .<Product, Product>chunk(3)
                                         .reader(reader)
                                         .writer(writer())
                                         .faultTolerant()
                                         .skipLimit(5)
                                         .skip(FlatFileParseException.class)
                                         .build();

    return jobBuilders.get("importProductsJob")
                      .repository(jobRepository)
                      .listener(loggerListener)
                      .start(decompress)
                      .next(readWriteProducts)
                      .build();
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:26,代码来源:ImportProductJobConfiguration.java


示例3: importProductsJob

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Bean
public Job importProductsJob() {
	Step importProductsStep = stepBuilders.get("importProductsStep")
	                                      .<String, String>chunk(5)
	                                      .reader(reader)
	                                      .processor(processor)
	                                      .writer(writer)
	                                      .faultTolerant()
	                                      .skipLimit(5)
	                                      .skip(FlatFileParseException.class)
	                                      .skip(DataIntegrityViolationException.class)
	                                      .listener(skipListener)
	                                      .build();

	return jobBuilders.get("importProductsJob")
	                  .start(importProductsStep)
	                  .build();
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:19,代码来源:SkipBehaviorConfiguration.java


示例4: doRead

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
/**
 * Byte단위로 읽어들인 한 라인을 ValueObject로 매핑
 * 
 * @return string corresponding to logical record according to
 *         {@link #setRecordSeparatorPolicy(RecordSeparatorPolicy)} (might
 *         span multiple lines in file).
 */
@Override
protected T doRead() throws Exception {
	if (noInput) {
		return null;
	}

	byte[] line = readLine();

	if (line == null) {
		return null;
	} else {
		try {
			return lineMapper.mapLine(line, lineCount);
		} catch (Exception ex) {
			throw new FlatFileParseException("Parsing error at line: "
					+ lineCount + " in resource=["
					+ resource.getDescription() + "], input=["
					+ line.toString() + "]", ex, line.toString(), lineCount);
		}
	}
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:29,代码来源:EgovFlatFileByteReader.java


示例5: onReadError

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@OnReadError
public void onReadError(Exception ex) {
    if (ex instanceof FlatFileParseException) {
        FlatFileParseException ffpe = (FlatFileParseException) ex;
        LOG.error("Error reading data on line '{}' - data: '{}'", ffpe.getLineNumber(), ffpe.getInput());
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:8,代码来源:LoggingBatchListener.java


示例6: onReadError

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
public final void onReadError(final Exception e) {
	logger.error("Read Error " + e.getMessage());
	if (e instanceof FlatFileParseException) {
		FlatFileParseException ffpe = (FlatFileParseException) e;
		StringBuffer message = new StringBuffer();
		message.append(ffpe.getMessage());
		final Annotation annotation = new Annotation();
		if (ffpe.getCause() != null) {
			message.append(" " + ffpe.getCause().getMessage());
			logger.debug("FlatFileParseException | " + ffpe.getMessage()
					+ " Cause " + ffpe.getCause().getMessage());
			if (ffpe.getCause().getClass()
					.equals(CannotFindRecordException.class)) {
				annotation.setCode(AnnotationCode.BadIdentifier);
				CannotFindRecordException cfre = (CannotFindRecordException) ffpe
						.getCause();
				annotation.setValue(cfre.getValue());
			} else if (ffpe.getCause().getClass()
					.equals(BindException.class)) {
				annotation.setCode(AnnotationCode.BadField);
				BindException be = (BindException) ffpe.getCause();
				annotation.setValue(be.getFieldError().getField());
			} else {
				annotation.setCode(AnnotationCode.BadRecord);
			}
		} else {
			logger.debug("FlatFileParseException | " + ffpe.getMessage());
		}

		annotation.setJobId(stepExecution.getJobExecutionId());
		annotation.setRecordType(getRecordType());
		annotation.setType(AnnotationType.Error);
		annotation.setText(message.toString());
		super.annotate(annotation);
	}
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:37,代码来源:DwCProcessingExceptionProcessListener.java


示例7: mapLine

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Override
public Map<String, Object> mapLine(String line, int lineNumber)
		throws Exception {
	Map<String, Object> result;
	try {
		JsonParser parser = factory.createParser(line);
		@SuppressWarnings("unchecked")
		Map<String, Object> token = parser.readValueAs(Map.class);
		result = token;
	}
	catch (Exception e) {
		throw new FlatFileParseException("Cannot parse line to JSON", e, line, lineNumber);
	}
	return result;
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:16,代码来源:Jackson2JsonLineMapper.java


示例8: importProducts

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Bean
public Job importProducts() {
	Step step1 = stepBuilders.get("decompress").tasklet(decompressTasklet).build();
	Step step2 = stepBuilders.get("readWriteProducts")
	                         .<String, Product>chunk(3).faultTolerant().skipLimit(5).skip(FlatFileParseException.class)
	                         .reader(reader).writer(writer())
	                         .build();

	return jobBuilders.get("readWriteProducts")
	                  .start(step1)
	                  .next(step2)
	                  .build();
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:14,代码来源:ImportProductsConfiguration.java


示例9: importProductsJob

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Bean
public Job importProductsJob(Tasklet dummyTasklet, ItemReader<Product> reader) {

    Step decompress = stepBuilders.get("decompress").tasklet(dummyTasklet).build();

    Step readWrite = stepBuilders.get("readWriteProducts")
                                 .<Product, Product>chunk(100)
                                 .reader(reader)
                                 .writer(writer())
                                 .faultTolerant()
                                 .skipLimit(5)
                                 .skip(FlatFileParseException.class)
                                 .build();

    Step generateReport = stepBuilders.get("generateReport").tasklet(dummyTasklet).build();

    Step sendReport = stepBuilders.get("sendReport").tasklet(dummyTasklet).build();

    Step clean = stepBuilders.get("clean").tasklet(dummyTasklet).build();

    return jobBuilders.get("importProductsJob")
                      .repository(jobRepository)
                      .listener(loggerListener)
                      .start(decompress)
                      .next(readWrite)
                      .next(skippedDecider()).on("SKIPPED").to(generateReport).next(sendReport)
                      .from(skippedDecider()).on("*").to(clean).end()
                      .build();

}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:31,代码来源:JobStructureComplexConfiguration.java


示例10: importProductsJob

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Bean
public Job importProductsJob(Tasklet dummyTasklet, ItemReader<Product> reader) {

    Step decompress = stepBuilders.get("decompress")
                                  .tasklet(dummyTasklet)
                                  .repository(jobRepository)
                                  .transactionManager(transactionManager)
                                  .build();

    Step readWrite = stepBuilders.get("readWriteProducts")
                                 .<Product, Product>chunk(100)
                                 .reader(reader)
                                 .writer(writer())
                                 .faultTolerant()
                                 .skipLimit(5)
                                 .skip(FlatFileParseException.class)
                                 .build();

    Step clean = stepBuilders.get("clean")
                             .tasklet(dummyTasklet)
                             .repository(jobRepository)
                             .transactionManager(transactionManager)
                             .build();

    return jobBuilders.get("importProductsJob")
                      .repository(jobRepository)
                      .listener(loggerListener)
                      .start(decompress)
                      .next(readWrite)
                      .next(clean)
                      .build();
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:33,代码来源:JobStructureSimpleConfiguration.java


示例11: onSkipInRead

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Override
public void onSkipInRead(Throwable t) {
	if (t instanceof FlatFileParseException) {
		FlatFileParseException ffpe = (FlatFileParseException) t;
		log.error(ffpe.getInput(), t);
	}
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:8,代码来源:Slf4jSkipListener.java


示例12: onSkipInRead

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Override
public void onSkipInRead(Throwable t) {
	if (t instanceof FlatFileParseException) {
		FlatFileParseException ffpe = (FlatFileParseException) t;
		SkippedProduct product = new SkippedProduct();
		product.setInput(ffpe.getInput());
		product.setLineNumber(ffpe.getLineNumber());
		em.persist(product);
		em.flush();
	}
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:12,代码来源:DatabaseSkipListener.java


示例13: execptionInReading

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Test
public void execptionInReading() throws Exception {
	when(service.reading())
			.thenReturn("1")
			.thenReturn("2")
			.thenReturn("3")
			.thenReturn("4")
			.thenReturn("5")
			.thenReturn("6")
			.thenThrow(new FlatFileParseException("", ""))
			.thenReturn("8")
			.thenReturn("9")
			.thenReturn("10")
			.thenReturn("11")
			.thenReturn("12")
			.thenReturn(null);

	JobParameters params = new JobParametersBuilder().addLong("time", System.currentTimeMillis())
	                                                 .toJobParameters();
	JobExecution exec = jobLauncher.run(job, params);

	assertThat(exec.getStatus()).isEqualTo(BatchStatus.COMPLETED);

	verify(service, times(13)).reading();
	verify(service, times(11)).processing(anyString());
	verify(service, times(11)).writing(anyString());
	verify(skipListener, times(1)).onSkipInRead(any(Throwable.class));

	assertRead(11, exec);
	assertWrite(11, exec);
	assertReadSkip(1, exec);
	assertProcessSkip(0, exec);
	assertWriteSkip(0, exec);
	assertCommit(3, exec);
	assertRollback(0, exec);
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:37,代码来源:SkipBehaviorTest.java


示例14: importProductsJob

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Bean
public Job importProductsJob() {
	Step importProductsStep = stepBuilders.get("importProductsStep")
	                                      .<Product, Product>chunk(3)
	                                      .reader(productReader)
	                                      .writer(productItemWriter())
	                                      .faultTolerant().skipLimit(2).skip(FlatFileParseException.class)
	                                      .listener(slf4jSkipListener())
	                                      .listener(databaseSkipListener())
	                                      .build();

	return jobBuilders.get("importProductsJob")
	                  .start(importProductsStep)
	                  .build();
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:16,代码来源:SkipConfiguration.java


示例15: onReadError

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Override
public void onReadError(Exception ex) {
	if (ex instanceof FlatFileParseException) {
		FlatFileParseException ffpe = (FlatFileParseException) ex;
		logger.error(String.format("Error reading data on line '%s' - data: '%s'", ffpe.getLineNumber(), ffpe.getInput()));
	}
	chunkNotificationsChannel.send(MessageBuilder.withPayload(new Notification(ex.getMessage(),true)).build());
}
 
开发者ID:ghillert,项目名称:spring-batch-integration-sample,代码行数:9,代码来源:PaymentChunkListener.java


示例16: exceptionInReadingThenWritingNoCallOnSkipListener

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Test
public void exceptionInReadingThenWritingNoCallOnSkipListener() throws Exception {
	when(service.reading())
			.thenReturn("1")
			.thenReturn("2")
			.thenReturn("3")
			.thenReturn("4")
			.thenReturn("5")
			.thenReturn("6")
			.thenThrow(new FlatFileParseException("", ""))
			.thenReturn("8")
			.thenReturn("9")
			.thenReturn("10")
			.thenReturn("11")
			.thenReturn("12")
			.thenReturn(null);

	final String toFailWriting = "9";
	doNothing().when(service).writing(argThat(new BaseMatcher<String>() {
		@Override
		public boolean matches(Object item) {
			return !toFailWriting.equals(item);
		}

		@Override
		public void describeTo(Description description) {}
	}));

	doThrow(new RuntimeException("")).when(service).writing(toFailWriting);

	JobParameters params = new JobParametersBuilder().addLong("time", System.currentTimeMillis())
	                                                 .toJobParameters();
	JobExecution exec = jobLauncher.run(job, params);
	assertThat(exec.getStatus()).isEqualTo(BatchStatus.FAILED);

	verify(service, times(11)).reading();
	verify(service, times(11)).processing(anyString());
	verify(service, times(8)).writing(anyString());

	// skip listener is not called, because transaction is rolled back
	// skip listener is called just before the commit!
	verify(skipListener, times(0)).onSkipInRead(any(Throwable.class));


	assertRead(10, exec);
	assertWrite(5, exec);
	assertReadSkip(1, exec);
	assertProcessSkip(0, exec);
	assertWriteSkip(0, exec);
	assertCommit(1, exec);
	assertRollback(2, exec);
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:53,代码来源:SkipBehaviorTest.java


示例17: skipPolicy

import org.springframework.batch.item.file.FlatFileParseException; //导入依赖的package包/类
@Bean
public ExceptionSkipPolicy skipPolicy() {
	return new ExceptionSkipPolicy(FlatFileParseException.class);
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:5,代码来源:SkipConfiguration.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Query类代码示例发布时间:2022-05-23
下一篇:
Java View类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap