diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index a2526ab2..c2d9562e 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -24,7 +24,7 @@ import java.io.StringWriter; /** * The format specification of a CSV file. - * + * * This class is immutable. */ public class CSVFormat implements Serializable { @@ -95,7 +95,7 @@ public class CSVFormat implements Serializable { * locale dependent, it might be necessary to customize this format to accomodate to your regional settings. *
* For example for parsing or generating a CSV file on a French system the following format will be used: - * + * ** CSVFormat fmt = CSVFormat.EXCEL.withDelimiter(';'); *@@ -120,8 +120,8 @@ public class CSVFormat implements Serializable { * 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 + * @see + * http://dev.mysql.com/doc/refman/5.1/en/load-data.html */ public static final CSVFormat MYSQL = PRISTINE @@ -132,7 +132,7 @@ public class CSVFormat implements Serializable { /** * Creates a customized CSV format. - * + * * @param delimiter * the char used for value separation * @param encapsulator @@ -167,10 +167,10 @@ 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) {
@@ -209,7 +209,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the character delimiting the values (typically ';', ',' or '\t').
- *
+ *
* @return the delimiter character
*/
public char getDelimiter() {
@@ -218,7 +218,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
@@ -236,7 +236,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the character used to encapsulate values containing special characters.
- *
+ *
* @return the encapsulator character
*/
public char getEncapsulator() {
@@ -245,7 +245,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
@@ -263,7 +263,7 @@ public class CSVFormat implements Serializable {
/**
* Returns whether an encapsulator has been defined.
- *
+ *
* @return {@code true} if an encapsulator is defined
*/
public boolean isEncapsulating() {
@@ -272,7 +272,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the character marking the start of a line comment.
- *
+ *
* @return the comment start marker.
*/
public char getCommentStart() {
@@ -281,9 +281,9 @@ 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
@@ -301,9 +301,9 @@ public class CSVFormat implements Serializable {
/**
* 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() {
@@ -312,7 +312,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the escape character.
- *
+ *
* @return the escape character
*/
public char getEscape() {
@@ -321,7 +321,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
@@ -339,7 +339,7 @@ public class CSVFormat implements Serializable {
/**
* Returns whether escape are being processed.
- *
+ *
* @return {@code true} if escapes are processed
*/
public boolean isEscaping() {
@@ -348,7 +348,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.
*/
@@ -358,7 +358,7 @@ public class CSVFormat implements Serializable {
/**
* Returns a copy of this format with the specified trimming behavior.
- *
+ *
* @param surroundingSpacesIgnored
* the trimming behavior, true to remove the surrounding spaces, false to leave the
* spaces as is.
@@ -371,7 +371,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.
*/
@@ -381,7 +381,7 @@ public class CSVFormat implements Serializable {
/**
* Returns a copy of this format with the specified empty line skipping behavior.
- *
+ *
* @param emptyLinesIgnored
* the empty line skipping behavior, true to ignore the empty lines between the records,
* false to translate empty lines to empty records.
@@ -394,7 +394,7 @@ public class CSVFormat implements Serializable {
/**
* Returns the line separator delimiting output records.
- *
+ *
* @return the line separator
*/
public String getLineSeparator() {
@@ -403,10 +403,10 @@ 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) {
@@ -421,20 +421,20 @@ public class CSVFormat implements Serializable {
/**
* Returns a copy of this format using the specified header. The header can either be parsed automatically from the
* input file with:
- *
+ *
* * CSVFormat format = aformat.withHeader(); *- * + * * or specified manually with: - * + * *
* CSVFormat format = aformat.withHeader("name", "email", "phone"); *- * + * * @param header * the header, null if disabled, empty if parsed automatically, user specified otherwise. - * + * * @return A copy of this format using the specified header */ public CSVFormat withHeader(String... header) { @@ -444,7 +444,7 @@ public class CSVFormat implements Serializable { /** * Parses the specified content. - * + * * @param in * the input stream */ @@ -454,7 +454,7 @@ public class CSVFormat implements Serializable { /** * Format the specified values. - * + * * @param values * the values to format */ diff --git a/src/main/java/org/apache/commons/csv/CSVLexer.java b/src/main/java/org/apache/commons/csv/CSVLexer.java index 0563b998..3f58fdb8 100644 --- a/src/main/java/org/apache/commons/csv/CSVLexer.java +++ b/src/main/java/org/apache/commons/csv/CSVLexer.java @@ -32,7 +32,7 @@ class CSVLexer extends Lexer { * Returns the next token. * * A token corresponds to a term, a record change or an end-of-file indicator. - * + * * @param token * an existing Token object to reuse. The caller is responsible to initialize the Token. * @return the next token found @@ -128,7 +128,7 @@ class CSVLexer extends Lexer { *
+ * Parsing of a csv-string having tabs as separators, '"' as an optional value encapsulator, and comments starting with + * '#': + *
* - *Parsing of a csv-string having tabs as separators, - * '"' as an optional value encapsulator, and comments starting with '#':
*- * CSVFormat format = new CSVFormat('\t', '"', '#'); - * Reader in = new StringReader("a\tb\nc\td"); - * List<CSVRecord> records = new CSVParser(in, format).getRecords(); + * CSVFormat format = new CSVFormat('\t', '"', '#'); + * Reader in = new StringReader("a\tb\nc\td"); + * List<CSVRecord> records = new CSVParser(in, format).getRecords(); ** - *
Parsing of a csv-string in Excel CSV format, using a for-each loop:
+ *+ * Parsing of a csv-string in Excel CSV format, using a for-each loop: + *
+ * ** Reader in = new StringReader("a;b\nc;d"); * CSVParser parser = new CSVParser(in, CSVFormat.EXCEL); @@ -54,11 +59,12 @@ import static org.apache.commons.csv.Token.Type.*; ** *
- * Internal parser state is completely covered by the format - * and the reader-state.
+ * Internal parser state is completely covered by the format and the reader-state. + * * - *see package documentation - * for more details
+ *+ * see package documentation for more details + *
*/ public class CSVParser implements Iterable- * In particular the reader supports a look-ahead option, - * which allows you to see the next char returned by + * In particular the reader supports a look-ahead option, which allows you to see the next char returned by * {@link #read()}. */ class ExtendedBufferedReader extends BufferedReader { @@ -65,12 +63,10 @@ class ExtendedBufferedReader extends BufferedReader { } /** - * Returns the last character that was read as an integer (0 to 65535). This - * will be the last character returned by any of the read methods. This will - * not include a character read using the {@link #peek()} method. If no - * 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}. + * Returns the last character that was read as an integer (0 to 65535). This will be the last character returned by + * any of the read methods. This will not include a character read using the {@link #peek()} method. If no + * 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 */ @@ -91,7 +87,7 @@ class ExtendedBufferedReader extends BufferedReader { for (int i = offset; i < offset + len; i++) { char ch = buf[i]; if (ch == LF) { - if (CR != (i > 0 ? buf[i-1]: lastChar)) { + if (CR != (i > 0 ? buf[i - 1] : lastChar)) { lineCounter++; } } else if (ch == CR) { @@ -109,14 +105,12 @@ class ExtendedBufferedReader extends BufferedReader { } /** - * Calls {@link BufferedReader#readLine()} which drops the line terminator(s). - * This method should only be called when processing a comment, otherwise - * information can be lost. + * Calls {@link BufferedReader#readLine()} which drops the line terminator(s). This method should only be called + * when processing a comment, otherwise information can be lost. *
- * Increments {@link #lineCounter} + * 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. */ @@ -135,12 +129,13 @@ 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. + * 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 + * @throws IOException + * if there is an error in reading */ int lookAhead() throws IOException { super.mark(1); diff --git a/src/main/java/org/apache/commons/csv/Lexer.java b/src/main/java/org/apache/commons/csv/Lexer.java index 20200501..31743b53 100644 --- a/src/main/java/org/apache/commons/csv/Lexer.java +++ b/src/main/java/org/apache/commons/csv/Lexer.java @@ -64,20 +64,20 @@ abstract class Lexer { // assume c is the escape char (normally a backslash) int c = in.read(); switch (c) { - case 'r': - return '\r'; - case 'n': - return '\n'; - case 't': - return '\t'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case ExtendedBufferedReader.END_OF_STREAM: - throw new IOException("EOF whilst processing escape sequence"); - default: - return c; + case 'r': + return '\r'; + case 'n': + return '\n'; + case 't': + return '\t'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case ExtendedBufferedReader.END_OF_STREAM: + throw new IOException("EOF whilst processing escape sequence"); + default: + return c; } } @@ -99,8 +99,7 @@ abstract class Lexer { } /** - * Greedy - accepts \n, \r and \r\n - * This checker consumes silently the second control-character... + * Greedy - accepts \n, \r and \r\n This checker consumes silently the second control-character... * * @return true if the given character is a line-terminator */ @@ -114,8 +113,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. + * 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. @@ -123,6 +121,7 @@ abstract class Lexer { boolean isStartOfLine(int c) { return c == '\n' || c == '\r' || c == ExtendedBufferedReader.UNDEFINED; } + /** * @return true if the given character indicates end of file */ diff --git a/src/main/java/org/apache/commons/csv/Token.java b/src/main/java/org/apache/commons/csv/Token.java index 42e4b775..0ceff9e3 100644 --- a/src/main/java/org/apache/commons/csv/Token.java +++ b/src/main/java/org/apache/commons/csv/Token.java @@ -65,6 +65,6 @@ class Token { // Provide toString method for IDE debugging @Override public String toString() { - return type.name()+" ["+content.toString()+"]"; + return type.name() + " [" + content.toString() + "]"; } }