diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java
index ccad0266..5e41cb5c 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -33,7 +33,7 @@ public class CSVFormat implements Serializable {
/** According to RFC 4180, line breaks are delimited by CRLF */
public static final String CRLF = "\r\n";
-
+
private final char delimiter;
private final char encapsulator;
private final char commentStart;
@@ -60,14 +60,14 @@ public class CSVFormat implements Serializable {
*/
static final CSVFormat PRISTINE = new CSVFormat(DISABLED, DISABLED, DISABLED, DISABLED, false, false, null, null);
- /**
- * Standard comma separated format, as for {@link #RFC4180} but allowing blank lines.
+ /**
+ * Standard comma separated format, as for {@link #RFC4180} but allowing blank lines.
*
*
withDelimiter(',')
*
withEncapsulator('"')
*
withEmptyLinesIgnored(true)
*
withLineSeparator(CRLF)
- *
+ *
*/
public static final CSVFormat DEFAULT =
PRISTINE.
@@ -83,7 +83,7 @@ public class CSVFormat implements Serializable {
*
withEncapsulator('"')
*
withLineSeparator(CRLF)
*
- *
+ *
*/
public static final CSVFormat RFC4180 =
PRISTINE.
@@ -99,7 +99,7 @@ public class CSVFormat implements Serializable {
*
* For example for parsing or generating a CSV file on a French system
* the following format will be used:
- *
+ *
*
*/
public static final CSVFormat EXCEL =
@@ -122,7 +122,7 @@ public class CSVFormat implements Serializable {
* LOAD DATA INFILE operations. This is a tab-delimited
* format with a LF character as the line separator. Values are not quoted
* and special characters are escaped with '\'.
- *
+ *
* @see http://dev.mysql.com/doc/refman/5.1/en/load-data.html
*/
public static final CSVFormat MYSQL =
@@ -168,9 +168,9 @@ public class CSVFormat implements Serializable {
/**
* Returns true if the given character is a line break character.
- *
+ *
* @param c the character to check
- *
+ *
* @return true if c is a line break character
*/
private static boolean isLineBreak(char c) {
@@ -184,19 +184,19 @@ public class CSVFormat implements Serializable {
if (delimiter == encapsulator) {
throw new IllegalArgumentException("The encapsulator character and the delimiter cannot be the same (\"" + encapsulator + "\")");
}
-
+
if (delimiter == escape) {
throw new IllegalArgumentException("The escape character and the delimiter cannot be the same (\"" + escape + "\")");
}
-
+
if (delimiter == commentStart) {
throw new IllegalArgumentException("The comment start character and the delimiter cannot be the same (\"" + commentStart + "\")");
}
-
+
if (encapsulator != DISABLED && encapsulator == commentStart) {
throw new IllegalArgumentException("The comment start character and the encapsulator cannot be the same (\"" + commentStart + "\")");
}
-
+
if (escape != DISABLED && escape == commentStart) {
throw new IllegalArgumentException("The comment start and the escape character cannot be the same (\"" + commentStart + "\")");
}
@@ -204,7 +204,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the character delimiting the values (typically ';', ',' or '\t').
- *
+ *
* @return the delimiter character
*/
public char getDelimiter() {
@@ -213,7 +213,7 @@ public class CSVFormat implements Serializable {
/**
* Returns a copy of this format using the specified delimiter character.
- *
+ *
* @param delimiter the delimiter character
* @return A copy of this format using the specified delimiter character
* @throws IllegalArgumentException thrown if the specified character is a line break
@@ -228,7 +228,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the character used to encapsulate values containing special characters.
- *
+ *
* @return the encapsulator character
*/
public char getEncapsulator() {
@@ -237,7 +237,7 @@ public class CSVFormat implements Serializable {
/**
* Returns a copy of this format using the specified encapsulator character.
- *
+ *
* @param encapsulator the encapsulator character
* @return A copy of this format using the specified encapsulator character
* @throws IllegalArgumentException thrown if the specified character is a line break
@@ -246,13 +246,13 @@ public class CSVFormat implements Serializable {
if (isLineBreak(encapsulator)) {
throw new IllegalArgumentException("The encapsulator cannot be a line break");
}
-
+
return new CSVFormat(delimiter, encapsulator, commentStart, escape, surroundingSpacesIgnored, emptyLinesIgnored, lineSeparator, header);
}
/**
* Returns whether an encapsulator has been defined.
- *
+ *
* @return {@code true} if an encapsulator is defined
*/
public boolean isEncapsulating() {
@@ -261,7 +261,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the character marking the start of a line comment.
- *
+ *
* @return the comment start marker.
*/
public char getCommentStart() {
@@ -270,10 +270,10 @@ public class CSVFormat implements Serializable {
/**
* Returns a copy of this format using the specified character as the comment start marker.
- *
+ *
* Note that the comment introducer character is only recognised
* at the start of a line.
- *
+ *
* @param commentStart the comment start marker
* @return A copy of this format using the specified character as the comment start marker
* @throws IllegalArgumentException thrown if the specified character is a line break
@@ -282,16 +282,16 @@ public class CSVFormat implements Serializable {
if (isLineBreak(commentStart)) {
throw new IllegalArgumentException("The comment start character cannot be a line break");
}
-
+
return new CSVFormat(delimiter, encapsulator, commentStart, escape, surroundingSpacesIgnored, emptyLinesIgnored, lineSeparator, header);
}
/**
* Specifies whether comments are supported by this format.
- *
+ *
* Note that the comment introducer character is only recognised
* at the start of a line.
- *
+ *
* @return true is comments are supported, false otherwise
*/
public boolean isCommentingEnabled() {
@@ -300,7 +300,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the escape character.
- *
+ *
* @return the escape character
*/
public char getEscape() {
@@ -309,7 +309,7 @@ public class CSVFormat implements Serializable {
/**
* Returns a copy of this format using the specified escape character.
- *
+ *
* @param escape the escape character
* @return A copy of this format using the specified escape character
* @throws IllegalArgumentException thrown if the specified character is a line break
@@ -318,13 +318,13 @@ public class CSVFormat implements Serializable {
if (isLineBreak(escape)) {
throw new IllegalArgumentException("The escape character cannot be a line break");
}
-
+
return new CSVFormat(delimiter, encapsulator, commentStart, escape, surroundingSpacesIgnored, emptyLinesIgnored, lineSeparator, header);
}
/**
* Returns whether escape are being processed.
- *
+ *
* @return {@code true} if escapes are processed
*/
public boolean isEscaping() {
@@ -333,7 +333,7 @@ public class CSVFormat implements Serializable {
/**
* Specifies whether spaces around values are ignored when parsing input.
- *
+ *
* @return true if spaces around values are ignored, false if they are treated as part of the value.
*/
public boolean isSurroundingSpacesIgnored() {
@@ -353,7 +353,7 @@ public class CSVFormat implements Serializable {
/**
* Specifies whether empty lines between records are ignored when parsing input.
- *
+ *
* @return true if empty lines between records are ignored, false if they are turned into empty records.
*/
public boolean isEmptyLinesIgnored() {
@@ -373,7 +373,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the line separator delimiting output records.
- *
+ *
* @return the line separator
*/
public String getLineSeparator() {
@@ -382,9 +382,9 @@ public class CSVFormat implements Serializable {
/**
* Returns a copy of this format using the specified output line separator.
- *
+ *
* @param lineSeparator the line separator to be used for output.
- *
+ *
* @return A copy of this format using the specified output line separator
*/
public CSVFormat withLineSeparator(String lineSeparator) {
@@ -415,7 +415,7 @@ public class CSVFormat implements Serializable {
/**
* Parses the specified content.
- *
+ *
* @param in the input stream
*/
public Iterable parse(Reader in) throws IOException {
@@ -424,7 +424,7 @@ public class CSVFormat implements Serializable {
/**
* Format the specified values.
- *
+ *
* @param values the values to format
*/
public String format(String... values) {
@@ -435,7 +435,7 @@ public class CSVFormat implements Serializable {
} catch (IOException e) {
// should not happen
throw new IllegalStateException(e);
- }
+ }
}
@Override
@@ -448,19 +448,19 @@ public class CSVFormat implements Serializable {
}
if (isEncapsulating()) {
sb.append(' ');
- sb.append("Encapsulator=<").append(encapsulator).append('>');
+ sb.append("Encapsulator=<").append(encapsulator).append('>');
}
if (isCommentingEnabled()) {
sb.append(' ');
sb.append("CommentStart=<").append(commentStart).append('>');
}
if (isEmptyLinesIgnored()) {
- sb.append(" EmptyLines:ignored");
+ sb.append(" EmptyLines:ignored");
}
if (isSurroundingSpacesIgnored()) {
- sb.append(" SurroundingSpaces:ignored");
+ sb.append(" SurroundingSpaces:ignored");
}
return sb.toString();
}
-
+
}
diff --git a/src/main/java/org/apache/commons/csv/CSVLexer.java b/src/main/java/org/apache/commons/csv/CSVLexer.java
index c23728d9..6741ecff 100644
--- a/src/main/java/org/apache/commons/csv/CSVLexer.java
+++ b/src/main/java/org/apache/commons/csv/CSVLexer.java
@@ -27,7 +27,7 @@ class CSVLexer extends Lexer {
public CSVLexer(CSVFormat format, ExtendedBufferedReader in) {
super(format, in);
}
-
+
/**
* Returns the next token.
*
@@ -92,7 +92,7 @@ class CSVLexer extends Lexer {
eol = isEndOfLine(c);
}
}
-
+
// ok, start of token reached: encapsulated, or token
if (isDelimiter(c)) {
// empty token return TOKEN("")
@@ -183,7 +183,7 @@ class CSVLexer extends Lexer {
*
* @param tkn the current token
* @return a valid token object
- * @throws IOException on invalid state:
+ * @throws IOException on invalid state:
* EOF before closing encapsulator or invalid character before delimiter or EOL
*/
private Token encapsulatedTokenLexer(Token tkn) throws IOException {
@@ -192,7 +192,7 @@ class CSVLexer extends Lexer {
int c;
while (true) {
c = in.read();
-
+
if (isEscape(c)) {
tkn.content.append((char) readEscape());
} else if (isEncapsulator(c)) {
diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java
index 35e464a5..41ef7b4e 100644
--- a/src/main/java/org/apache/commons/csv/CSVParser.java
+++ b/src/main/java/org/apache/commons/csv/CSVParser.java
@@ -66,7 +66,7 @@ public class CSVParser implements Iterable {
private final Map headerMapping;
// the following objects are shared to reduce garbage
-
+
/** A record buffer for getRecord(). Grows as necessary and is reused. */
private final List record = new ArrayList();
private final Token reusableToken = new Token();
@@ -90,9 +90,9 @@ public class CSVParser implements Iterable {
*/
public CSVParser(Reader input, CSVFormat format) throws IOException {
format.validate();
-
+
this.lexer = new CSVLexer(format, new ExtendedBufferedReader(input));
-
+
this.headerMapping = initializeHeader(format);
}
@@ -166,9 +166,9 @@ public class CSVParser implements Iterable {
break;
}
} while (reusableToken.type == TOKEN);
-
+
if (!record.isEmpty()) {
- result = new CSVRecord(record.toArray(new String[record.size()]), headerMapping,
+ result = new CSVRecord(record.toArray(new String[record.size()]), headerMapping,
sb == null ? null : sb.toString());
}
return result;
@@ -210,12 +210,12 @@ public class CSVParser implements Iterable {
public Iterator iterator() {
return new Iterator() {
private CSVRecord current;
-
+
public boolean hasNext() {
if (current == null) {
current = getNextRecord();
}
-
+
return current != null;
}
@@ -230,10 +230,10 @@ public class CSVParser implements Iterable {
throw new NoSuchElementException("No more CSV records available");
}
}
-
+
return next;
}
-
+
private CSVRecord getNextRecord() {
try {
return getRecord();
diff --git a/src/main/java/org/apache/commons/csv/CSVPrinter.java b/src/main/java/org/apache/commons/csv/CSVPrinter.java
index a795c1ef..ccea0a60 100644
--- a/src/main/java/org/apache/commons/csv/CSVPrinter.java
+++ b/src/main/java/org/apache/commons/csv/CSVPrinter.java
@@ -62,7 +62,7 @@ public class CSVPrinter {
/**
* Flush the underlying stream.
- *
+ *
* @throws IOException
*/
public void flush() throws IOException {
@@ -127,7 +127,7 @@ public class CSVPrinter {
}
- private void print(CharSequence value, int offset, int len) throws IOException {
+ private void print(CharSequence value, int offset, int len) throws IOException {
if (format.isEncapsulating()) {
printAndEncapsulate(value, offset, len);
} else if (format.isEscaping()) {
@@ -284,7 +284,7 @@ public class CSVPrinter {
// null values are considered empty
value = "";
}
-
+
if (!checkForEscape) {
// write directly from string
printSep();
diff --git a/src/main/java/org/apache/commons/csv/CSVRecord.java b/src/main/java/org/apache/commons/csv/CSVRecord.java
index 09da4270..bd25b106 100644
--- a/src/main/java/org/apache/commons/csv/CSVRecord.java
+++ b/src/main/java/org/apache/commons/csv/CSVRecord.java
@@ -26,11 +26,11 @@ import java.util.Map;
* A CSV record
*/
public class CSVRecord implements Serializable, Iterable {
-
+
private static final long serialVersionUID = 1L;
private static final String[] EMPTY_STRING_ARRAY = new String[0];
-
+
/** The values of the record */
private final String[] values;
diff --git a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
index e1f42e3e..663aab9f 100644
--- a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
+++ b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
@@ -71,7 +71,7 @@ class ExtendedBufferedReader extends BufferedReader {
* character has been read then this will return {@link #UNDEFINED}. If the
* end of the stream was reached on the last read then this will return
* {@link #END_OF_STREAM}.
- *
+ *
* @return the last character that was read
*/
int readAgain() {
@@ -83,16 +83,16 @@ class ExtendedBufferedReader extends BufferedReader {
if (length == 0) {
return 0;
}
-
+
int len = super.read(buf, offset, length);
-
+
if (len > 0) {
for (int i = offset; i < offset + len; i++) {
char ch = buf[i];
if (ch == LF) {
if (CR != (i > 0 ? buf[i-1]: lastChar)) {
- lineCounter++;
+ lineCounter++;
}
} else if (ch == CR) {
lineCounter++;
@@ -104,7 +104,7 @@ class ExtendedBufferedReader extends BufferedReader {
} else if (len == -1) {
lastChar = END_OF_STREAM;
}
-
+
return len;
}
@@ -115,9 +115,9 @@ class ExtendedBufferedReader extends BufferedReader {
*
* Increments {@link #lineCounter}
*
- * Sets {@link #lastChar} to {@link #END_OF_STREAM} at EOF,
- * otherwise to LF
- *
+ * Sets {@link #lastChar} to {@link #END_OF_STREAM} at EOF,
+ * otherwise to LF
+ *
* @return the line that was read, or null if reached EOF.
*/
@Override
@@ -137,9 +137,9 @@ class ExtendedBufferedReader extends BufferedReader {
/**
* Returns the next character in the current reader without consuming it. So
* the next call to {@link #read()} will still return this value.
- *
+ *
* @return the next character
- *
+ *
* @throws IOException if there is an error in reading
*/
int lookAhead() throws IOException {
diff --git a/src/main/java/org/apache/commons/csv/Lexer.java b/src/main/java/org/apache/commons/csv/Lexer.java
index c06f2a70..20200501 100644
--- a/src/main/java/org/apache/commons/csv/Lexer.java
+++ b/src/main/java/org/apache/commons/csv/Lexer.java
@@ -27,17 +27,17 @@ abstract class Lexer {
private final boolean isEncapsulating;
private final boolean isEscaping;
private final boolean isCommentEnabled;
-
+
private final char delimiter;
private final char escape;
private final char encapsulator;
private final char commmentStart;
-
+
final boolean surroundingSpacesIgnored;
final boolean emptyLinesIgnored;
-
+
final CSVFormat format;
-
+
/** The input stream */
final ExtendedBufferedReader in;
@@ -116,7 +116,7 @@ abstract class Lexer {
/**
* Checks if the current character represents the start of a line:
* a CR, LF or is at the start of the file.
- *
+ *
* @param c
* @return true if the character is at the start of a line.
*/
@@ -131,7 +131,7 @@ abstract class Lexer {
}
abstract Token nextToken(Token reusableToken) throws IOException;
-
+
boolean isDelimiter(int c) {
return c == delimiter;
}
diff --git a/src/main/java/org/apache/commons/csv/Token.java b/src/main/java/org/apache/commons/csv/Token.java
index 045fee5d..b8c89f6f 100644
--- a/src/main/java/org/apache/commons/csv/Token.java
+++ b/src/main/java/org/apache/commons/csv/Token.java
@@ -28,30 +28,30 @@ class Token {
/** length of the initial token (content-)buffer */
private static final int INITIAL_TOKEN_LENGTH = 50;
-
+
enum Type {
/** Token has no valid content, i.e. is in its initialized state. */
INVALID,
-
+
/** Token with content, at beginning or in the middle of a line. */
TOKEN,
-
+
/** Token (which can have content) when end of file is reached. */
EOF,
-
+
/** Token with content when end of a line is reached. */
EORECORD,
-
+
/** Token is a comment line */
COMMENT
}
-
+
/** Token type */
Token.Type type = INVALID;
-
+
/** The content buffer. */
StringBuilder content = new StringBuilder(INITIAL_TOKEN_LENGTH);
-
+
/** Token ready flag: indicates a valid token with content (ready for the parser). */
boolean isReady;
diff --git a/src/main/java/org/apache/commons/csv/package-info.java b/src/main/java/org/apache/commons/csv/package-info.java
index 81b64317..41e13fad 100644
--- a/src/main/java/org/apache/commons/csv/package-info.java
+++ b/src/main/java/org/apache/commons/csv/package-info.java
@@ -17,11 +17,11 @@
/**
* Apache Commons CSV Format Support.
- *
+ *
*
CSV (or its dialects) are widely used as interfaces to legacy systems or
* manual data-imports. Basically CSV stands for "Comma Separated Values" but
* this simple abbreviation leads to more confusion than definitions.
- *
+ *
*
Common to all file dialects is its basic structure: The CSV data-format
* is record oriented, whereas each record starts on a new textual line. A
* record is build of a list of values. Keep in mind that not all records
@@ -30,41 +30,41 @@
* csv := records*
* record := values*
*
- *
+ *
*
The following list contains the csv aspects the Commons CSV parser supports:
*
*
Separators (for lines)
*
The record separators are hardcoded and cannot be changed. The must be '\r', '\n' or '\r\n'.
- *
+ *
*
Delimiter (for values)
*
The delimiter for values is freely configurable (default ',').
- *
+ *
*
Comments
*
Some CSV-dialects support a simple comment syntax. A comment is a record
* which must start with a designated character (the commentStarter). A record
* of this kind is treated as comment and gets removed from the input (default none)
- *
+ *
*
Encapsulator
*
Two encapsulator characters (default '"') are used to enclose -> complex values.
- *
+ *
*
Simple values
- *
A simple value consist of all characters (except the delimiter) until
+ *
A simple value consist of all characters (except the delimiter) until
* (but not including) the next delimiter or a record-terminator. Optionally
* all surrounding whitespaces of a simple value can be ignored (default: true).
- *
+ *
*
Complex values
*
Complex values are encapsulated within a pair of the defined encapsulator characters.
* The encapsulator itself must be escaped or doubled when used inside complex values.
* Complex values preserve all kind of formatting (including newlines -> multiline-values)
- *
+ *
*
Empty line skipping
- *
Optionally empty lines in CSV files can be skipped.
+ *
Optionally empty lines in CSV files can be skipped.
* Otherwise, empty lines will return a record with a single empty value.
*
- *
- *
In addition to individually defined dialects, two predefined dialects (strict-csv, and excel-csv)
+ *
+ *
In addition to individually defined dialects, two predefined dialects (strict-csv, and excel-csv)
* can be set directly.
- *
+ *
*
Example usage:
*
* Reader in = new StringReader("a,b,c");
diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
index 784b296c..abe26ab8 100644
--- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You 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.
@@ -45,7 +45,7 @@ import org.junit.runners.Parameterized.Parameters;
public class CSVFileParserTest {
private static final File BASE = new File("src/test/resources/CSVFileParser");
-
+
private final BufferedReader testData;
private final String testName;
@@ -67,7 +67,7 @@ public class CSVFileParserTest {
public static Collection