Example usage for org.springframework.batch.item.file.mapping PassThroughLineMapper PassThroughLineMapper

List of usage examples for org.springframework.batch.item.file.mapping PassThroughLineMapper PassThroughLineMapper

Introduction

In this page you can find the example usage for org.springframework.batch.item.file.mapping PassThroughLineMapper PassThroughLineMapper.

Prototype

PassThroughLineMapper

Source Link

Usage

From source file:de.langmi.spring.batch.examples.readers.file.flatfileitemreader.FlatFileItemReaderTest.java

/**
 * Test should read succesfully./*from  w  w w .  j  av a2s  .  c o  m*/
 *
 * @throws Exception 
 */
@Test
public void testSuccessfulReading() throws Exception {
    // init reader
    reader.setLineMapper(new PassThroughLineMapper());
    reader.setResource(new FileSystemResource(INPUT_FILE));
    // open, provide "mock" ExecutionContext
    reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext());
    // read
    try {
        int count = 0;
        String line;
        while ((line = reader.read()) != null) {
            assertEquals(String.valueOf(count), line);
            count++;
        }
        assertEquals(EXPECTED_COUNT, count);
    } catch (Exception e) {
        throw e;
    } finally {
        reader.close();
    }
}

From source file:de.langmi.spring.batch.examples.readers.file.peekable.SimplePeekableItemReaderTest.java

/**
 * Test should read succesfully.//from w w  w  .j  a v a2  s. c  o m
 *
 * @throws Exception 
 */
@Test
public void testSuccessfulPeekAhead() throws Exception {
    // init delegate
    delegateReader.setLineMapper(new PassThroughLineMapper());
    delegateReader.setResource(new FileSystemResource(INPUT_FILE));
    // init peekable
    SingleItemPeekableItemReader<String> peekable = new SingleItemPeekableItemReader<String>();
    peekable.setDelegate(delegateReader);
    // open, provide "mock" ExecutionContext
    peekable.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext());
    // read
    try {
        int count = 0;
        String line;
        while ((line = peekable.read()) != null) {
            assertEquals(String.valueOf(count), line);
            // test for peek
            String lineAhead = peekable.peek();
            if (count + 1 < EXPECTED_COUNT) {
                assertEquals(String.valueOf(count + 1), lineAhead);
            } else {
                assertNull(lineAhead);
            }
            count++;
        }
        assertEquals(EXPECTED_COUNT, count);
    } catch (Exception e) {
        throw e;
    } finally {
        peekable.close();
    }
}

From source file:de.codecentric.batch.jobs.FlatFileJobConfiguration.java

@Bean
public ItemReader<String> reader() {
    FlatFileItemReader<String> reader = new FlatFileItemReader<String>();
    reader.setResource(new ClassPathResource("in-javaconfig.txt"));
    reader.setLineMapper(new PassThroughLineMapper());
    return reader;
}

From source file:de.langmi.spring.batch.examples.readers.file.peekable.SimplePeekableItemReaderTest.java

/**
 * Test should read succesfully./*from   w  w w  .  jav  a2 s .  com*/
 *
 * @throws Exception 
 */
@Test
public void testSuccessfulReading() throws Exception {
    // init delegate
    delegateReader.setLineMapper(new PassThroughLineMapper());
    delegateReader.setResource(new FileSystemResource(INPUT_FILE));
    // init peekable
    SingleItemPeekableItemReader<String> peekable = new SingleItemPeekableItemReader<String>();
    peekable.setDelegate(delegateReader);
    // open, provide "mock" ExecutionContext
    peekable.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext());
    // read
    try {
        int count = 0;
        String line;
        while ((line = peekable.read()) != null) {
            assertEquals(String.valueOf(count), line);
            count++;
        }
        assertEquals(EXPECTED_COUNT, count);
    } catch (Exception e) {
        throw e;
    } finally {
        peekable.close();
    }
}

From source file:de.langmi.spring.batch.examples.readers.support.CompositeItemStreamReaderTest.java

/**
 * Helpermethod to create FlatFileItemReader, sets the name too, to make restart
 * scenario possible - otherwise one flatFileItemReader would overwrite the 
 * other (in context).//from w  w  w .  j  a v  a  2  s .co m
 *
 * @param inputFile
 * @return configured FlatFileItemReader cast as ItemStreamReader
 */
private ItemStreamReader<String> createFlatFileItemReader(final String inputFile) {
    FlatFileItemReader<String> ffir = new FlatFileItemReader<String>();
    // init reader
    ffir.setLineMapper(new PassThroughLineMapper());
    ffir.setResource(new FileSystemResource(inputFile));
    ffir.setName(inputFile);

    return (ItemStreamReader<String>) ffir;
}

From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReaderTest.java

/**
 * Helper method to setup the used MultiResourceItemReader.
 *
 * @param mReader//from w  w  w  . j a  v  a  2  s  . c  o m
 * @throws Exception 
 */
private void generalMultiResourceReaderSetup(ZipMultiResourceItemReader<String> mReader) throws Exception {
    // setup delegate
    FlatFileItemReader<String> reader = new FlatFileItemReader<String>();
    reader.setLineMapper(new PassThroughLineMapper());
    mReader.setDelegate(reader);
}

From source file:de.langmi.spring.batch.examples.readers.file.archive.ArchiveMultiResourceItemReaderTest.java

/**
 * Helper method to setup the used MultiResourceItemReader.
 *
 * @param mReader//from   w  ww.j a  va  2s . c o  m
 * @throws Exception 
 */
private void generalMultiResourceReaderSetup(ArchiveMultiResourceItemReader<String> mReader) throws Exception {
    // setup delegate
    FlatFileItemReader<String> reader = new FlatFileItemReader<String>();
    reader.setLineMapper(new PassThroughLineMapper());
    mReader.setDelegate(reader);
}