Results 1 to 8 of 8

Thread: Writing Tab Delimited files using DelimitedLineAggregator

  1. #1

    Default Writing Tab Delimited files using DelimitedLineAggregator

    I am trying to create a tab delimited file using the FlatFileItemWriter and the DelimitedLineAggregator. However when I specify "\t" as the delimiter it puts the litteral characters "\t" and not an actual tab.

    Examlple config:
    Code:
    <bean id="fileWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
    		<property name="resource" ref="outputFile" />
    		<property name="fieldSetCreator" ref="fieldSetCreator">
    		<property name="lineAggregator">
    			<bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
    				<property name="delimiter" value="\t"/>
    			</bean>
    		</property>
    </bean>
    Example out:
    Code:
    \ta\tb\tc\td\te

  2. #2
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    I just did a quick unit test, and don't see any issue:

    Code:
    	public void testTabDelimited(){
    		
    		aggregator = new DelimitedLineAggregator();
    		aggregator.setDelimiter("\t");
    		
    		String[] args = { "a", "bc", "def" };
    		String expectedResult = "a	bc	def";
    		String result = aggregator.aggregate(new DefaultFieldSet(args));
    		assertEquals(result, expectedResult);
    	}
    Is it possible that Spring is interpreting it as literal, instead of a tab?

  3. #3

    Default

    Yes I believe that Spring might be treating it as a literal before setting it in the DelimitedLineAggregator. Is there a way to force Spring to keep it as the tab character?

  4. #4
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    I'm not sure, I've never ran into an issue like this before. You might try posting the question in the general DI forum to see if someone has had the same issue.

  5. #5
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    Did you get any response?
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  6. #6
    Join Date
    Apr 2009
    Posts
    4

    Default

    I have noticed this problem as well, but it appears using the DelimitedLineTokenizer.DELIMITER_TAB value as the delimiter works. In a config file, then, it looks something like this:

    Code:
    <beans:property name="delimiter">
       <util:constant static-field="org.springframework.batch.item.file.transform.DelimitedLineTokenizer.DELIMITER_TAB"/>
    </beans:property>

  7. #7
    Join Date
    May 2009
    Posts
    1

    Default

    Hi,
    please try using the the sequence
    "&#38;#9;"(using encoding UTF-8) instead of using \t.

    Code:
    	
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" ...>
    ...			
    <property name="delimiter" value="&#38;#9;"/>

  8. #8
    Join Date
    Dec 2011
    Posts
    1

    Default

    I tried the following and it worked

    Code:
    	
    <property name="lineAggregator">
    	<bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator" p:delimiter="&amp;#9;" />
    </property>

Posting Permissions

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