001/* 002 * Copyright 2006-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.batch.item.file.transform; 017 018import org.springframework.util.StringUtils; 019 020/** 021 * A {@link LineAggregator} implementation that converts an object into a 022 * delimited list of strings. The default delimiter is a comma. 023 * 024 * @author Dave Syer 025 * 026 */ 027public class DelimitedLineAggregator<T> extends ExtractorLineAggregator<T> { 028 029 private String delimiter = ","; 030 031 /** 032 * Public setter for the delimiter. 033 * @param delimiter the delimiter to set 034 */ 035 public void setDelimiter(String delimiter) { 036 this.delimiter = delimiter; 037 } 038 039 @Override 040 public String doAggregate(Object[] fields) { 041 return StringUtils.arrayToDelimitedString(fields, this.delimiter); 042 } 043 044}