Results 1 to 3 of 3

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

  1. #1
    Join Date
    Jul 2009
    Posts
    27

    Default 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. #2
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    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.

  3. #3
    Join Date
    Jul 2009
    Posts
    27

    Default

    Thanks a lot, strict works great.

Posting Permissions

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