Announcement Announcement Module
Collapse
No announcement yet.
FixedLength giving issues while trying to fetch only a subset of values Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FixedLength giving issues while trying to fetch only a subset of values

    I do have a file which have many records or columns in a single row. This file is being used across multiple systems. Hence not all fields are required for my requirement. Hence if i set only a subset of values as shown below

    <beans:bean
    class="org.springframework.batch.item.file.transfo rm.FixedLengthTokenizer">
    <beansroperty name="names" value="ab,bc,cd,de,ef" />
    <beansroperty name="columns" value="26-34,55-55,138-141,186-186,361-369" />
    </beans:bean>

    I get an exception as below

    Caused by: org.springframework.batch.item.file.transform.Inco rrectLineLengthException: Line is longer than max range 369
    at org.springframework.batch.item.file.transform.Fixe dLengthTokenizer.doTokenize(FixedLengthTokenizer.j ava:126)
    at org.springframework.batch.item.file.transform.Abst ractLineTokenizer.tokenize(AbstractLineTokenizer.j ava:82)
    at org.springframework.batch.item.file.mapping.Defaul tLineMapper.mapLine(DefaultLineMapper.java:46)
    ... 94 more


    Do we have to do anything special to fetch only subset of values

  • #2
    This is a shortcoming of this particular implementation...you HAVE to process all the data in each record even if you don't need it....you can't pluck a subset of the data.

    Edit: Looks like they may have recently changed the api? There is now a 'strict' flag on the tokenizer (so the above isn't true anymore):

    http://static.springsource.org/sprin...Strict(boolean)

    Public setter for the strict flag. If true (the default) then lines must be precisely the length specified by the columns. If false then shorter lines will be tolerated and padded with empty columns, and longer strings will simply be truncated.

    Comment


    • #3
      Thanks a lot, strict works great.

      Comment

      Working...
      X