List of usage examples for org.springframework.batch.item ItemStreamReader read
@Nullable
T read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException;
From source file:de.langmi.spring.batch.examples.readers.support.CompositeItemStreamReader.java
@Override public T read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { // read from all registered readers List items = new ArrayList(); for (ItemStreamReader<?> itemReaderStream : itemReaderStreams) { items.add(itemReaderStream.read()); }//from w w w . j a va 2 s . co m // delegate to mapper return unifyingMapper.mapItems(items); }
From source file:com.create.batch.TicketReaderFactoryTest.java
@Test(expected = FlatFileParseException.class) public void testCreateReaderAndFailToRead() throws Exception { // given/*from w w w . j a va2 s . c o m*/ 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 }
From source file:com.create.batch.TicketReaderFactoryTest.java
@Test public void testCreateReaderAndReadCorrectData() throws Exception { // given//from www.ja v a2 s . co m final ExecutionContext executionContext = mock(ExecutionContext.class); final LocalDate date = LocalDate.of(2015, 12, 20); // when final ItemStreamReader<Ticket> reader = factory.createReader(new ClassPathResource("tickets.csv")); final Ticket ticket; try { reader.open(executionContext); ticket = reader.read(); } finally { reader.close(); } // then assertThat(ticket, notNullValue()); assertThat(ticket.getTag(), equalTo("Ticket_0")); assertThat(ticket.getDate(), equalTo(Date.valueOf(date))); assertThat(ticket.getContent(), equalTo("Test ticket")); }
From source file:egovframework.rte.bat.core.item.composite.reader.EgovCompositeFileReader.java
public T read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { Object[] items = new Object[itemReaderList.size()]; int count = 0; int flagCount = 0; if (returnType.toUpperCase().equals("READER")) { for (ItemStreamReader<?> itemReader : itemReaderList) { items[count] = itemReader;//from w ww . ja v a 2s.co m count++; } } else { for (ItemStreamReader<?> itemReader : itemReaderList) { Object o = null; if ((o = itemReader.read()) == null) { flagCount = flagCount + 1; } else { items[count] = o; } count++; if (flagCount == itemReaderList.size()) { return null; } } } return itemsMapper.mapItems(items); }
From source file:org.beanio.spring.SpringTest.java
/** * Test standalone flat file reader configuration. *//*from w ww. j a v a 2s . co m*/ @Test @SuppressWarnings("unchecked") public void testItemReader() throws Exception { ItemStreamReader<Map<String, Object>> reader = (ItemStreamReader<Map<String, Object>>) context .getBean("itemReader-standalone"); assertNotNull(reader); try { reader.open(new ExecutionContext()); Map<String, Object> map = reader.read(); assertNotNull(map); assertEquals(new Integer(1), map.get("id")); assertEquals("John", map.get("name")); } finally { reader.close(); } }
From source file:org.beanio.spring.SpringTest.java
@Test @SuppressWarnings("unchecked") public void testRestartItemReader() throws Exception { ItemStreamReader<Map<String, Object>> reader = (ItemStreamReader<Map<String, Object>>) context .getBean("itemReader-restart"); assertNotNull(reader);/*from w w w. ja va2 s.c o m*/ try { ExecutionContext executionContext = new ExecutionContext(); executionContext.put("BeanIOFlatFileItemReader.read.count", new Integer(2)); reader.open(executionContext); Map<String, Object> map = reader.read(); assertNotNull(map); assertEquals(new Integer(3), map.get("id")); assertEquals("Joe", map.get("name")); } finally { reader.close(); } }
From source file:org.springframework.batch.core.scope.StepScopePerformanceTests.java
private int doTest(String name, String test) throws Exception { @SuppressWarnings("unchecked") ItemStreamReader<String> reader = (ItemStreamReader<String>) applicationContext.getBean(name); reader.open(new ExecutionContext()); StopWatch stopWatch = new StopWatch(test); stopWatch.start();//from ww w . j a v a 2 s . c o m int count = 0; while (reader.read() != null) { // do nothing count++; } stopWatch.stop(); reader.close(); logger.info(stopWatch.shortSummary()); return count; }