Announcement Announcement Module
Collapse
No announcement yet.
Writing Tab Delimited files using DelimitedLineAggregator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?

    Comment


    • #3
      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?

      Comment


      • #4
        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.

        Comment


        • #5
          Did you get any response?

          Comment


          • #6
            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>

            Comment


            • #7
              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;"/>

              Comment


              • #8
                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>

                Comment

                Working...
                X