Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2006-2007 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.batch.item.file.separator;
 
A RecordSeparatorPolicy that treats all lines as record endings, as long as they do not have unterminated quotes, and do not end in a continuation marker.

Author(s):
Dave Syer
 
 
 	private static final String QUOTE = "\"";
 
 	private static final String CONTINUATION = "\\";
 
 	private String quoteCharacter = ;
 
Default constructor.
 
 		this();
 	}

Convenient constructor with quote character as parameter.
 
 	public DefaultRecordSeparatorPolicy(String quoteCharacter) {
 		this(quoteCharacter);
 	}

Convenient constructor with quote character and continuation marker as parameters.
 
 	public DefaultRecordSeparatorPolicy(String quoteCharacterString continuation) {
 		super();
 		this. = continuation;
 		this. = quoteCharacter;
 	}

Public setter for the quoteCharacter. Defaults to double quote mark.

Parameters:
quoteCharacter the quoteCharacter to set
 
 	public void setQuoteCharacter(String quoteCharacter) {
 		this. = quoteCharacter;
 	}

Public setter for the continuation. Defaults to back slash.

Parameters:
continuation the continuation to set
 
 	public void setContinuation(String continuation) {
 		this. = continuation;
 	}

Return true if the line does not have unterminated quotes (delimited by "), and does not end with a continuation marker ('\'). The test for the continuation marker ignores whitespace at the end of the line.

 
 	public boolean isEndOfRecord(String line) {
 		return !isQuoteUnterminated(line) && !isContinued(line);
 	}

If we are in an unterminated quote, add a line separator. Otherwise remove the continuation marker (plus whitespace at the end) if it is there.

 
 	public String preProcess(String line) {
		if (isQuoteUnterminated(line)) {
			return line + "\n";
		}
		if (isContinued(line)) {
			return line.substring(0, line.lastIndexOf());
		}
		return line;
	}

Determine if the current line (or buffered concatenation of lines) contains an unterminated quote, indicating that the record is continuing onto the next line.

Parameters:
result
Returns:
	private boolean isQuoteUnterminated(String line) {
		return StringUtils.countOccurrencesOf(line) % 2 != 0;
	}

Determine if the current line (or buffered concatenation of lines) ends with the continuation marker, indicating that the record is continuing onto the next line.

Parameters:
result
Returns:
	private boolean isContinued(String line) {
		if (line == null) {
			return false;
		}
		return line.trim().endsWith();
	}
New to GrepCode? Check out our FAQ X