Results 1 to 5 of 5

Thread: FlatFileItemReader: Parsing file containing sequnce of characters as record separator

  1. #1
    Join Date
    Jun 2009
    Posts
    5

    Default FlatFileItemReader: Parsing file containing sequnce of characters as record separator

    I have a file that needs to be parsed and broken into Objects. I'm using FlatFileItemReader for this.

    The problem is that the file contains this sequence of characters as record separator - Ç{BEG}Ç
    and Ç as field separator
    Configuring Ç{BEG}Ç string as record separator does not work, it just returns the very first line of file and stops.

    I'm guessing this is because the file contains no new lines and the code internally still depends on plain old readLine() which requires a new line character.

    Can someone suggest a clean way to handle this?

    Sample data:
    item11Çitem12Çitem13ÇÇ{BEG}Çitem21Çitem22Çitem23ÇÇ {BEG}Çitem31Çitem32Çitem33ÇÇ{BEG}Ç

  2. #2
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    How about:

    Code:
    sed -ie 's/Ç{BEG}Ç/\n/g' myfile.txt

  3. #3
    Join Date
    Jun 2009
    Posts
    5

    Default

    Thanks Dave

    I'm looking for a java/spring batch based solution. Ideally, I would like to just configure and wire existing classes into some reader or write the bare minimum classes of my own which could be plugged into batch framework. While this is not a difficult problem to solve, I'm just looking for a clean solution and I want to be sure that I'm not missing any existing feature of spring batch before writing my own class.

    What I'm wondering is Record Separator Policy is supposed to do exactly this - being able to customize record separator and not depend on newlines. But it isn't working as expected.

  4. #4
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    I couldn't find a JIRA for this so I created one (http://jira.springframework.org/browse/BATCH-1356). In the meantime you have to duplicate a lot of FlatFileItemReader, and provide it with a way to scan a character stream that doesn't depend on java.io.BufferedReader.

  5. #5
    Join Date
    Jun 2009
    Posts
    5

    Default

    Thanks Dave, I see that it has been fixed in the latest release.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •