Skip to content

Commit 7bd9d1d

Browse files
committed
Updated the Javadoc
git-svn-id: https://svn.apache.org/repos/asf/commons/sandbox/csv/trunk@1297043 13f79535-47bb-0310-9956-ffa450edef68
1 parent 312f5b0 commit 7bd9d1d

3 files changed

Lines changed: 41 additions & 50 deletions

File tree

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class CSVFormat implements Cloneable, Serializable {
4646
*/
4747
public static final char DISABLED = '\ufffe';
4848

49-
/** Standard comma separated format as defined by RFC 4180. */
49+
/** Standard comma separated format as defined by <a href="http://tools.ietf.org/html/rfc4180">RFC 4180</a>. */
5050
public static final CSVFormat DEFAULT = new CSVFormat(',', '"', DISABLED, DISABLED, true, true, false, true);
5151

5252
/** Excel file format (using a comma as the value delimiter). */
@@ -57,26 +57,33 @@ public class CSVFormat implements Cloneable, Serializable {
5757

5858

5959
/**
60-
* Creates a CSVFormat with the default parameters.
60+
* Creates a CSV format with the default parameters.
6161
*/
6262
public CSVFormat() {
6363
}
6464

65+
/**
66+
* Creates a customized CSV format.
67+
*
68+
* @param delimiter the char used for value separation
69+
* @param encapsulator the char used as value encapsulation marker
70+
* @param commentStart the char used for comment identification
71+
*/
6572
public CSVFormat(char delimiter, char encapsulator, char commentStart) {
6673
this(delimiter, encapsulator, commentStart, DISABLED, true, true, false, true);
6774
}
6875

6976
/**
70-
* Customized CSV format constructor.
77+
* Creates a customized CSV format.
7178
*
72-
* @param delimiter a char used for value separation
73-
* @param encapsulator a char used as value encapsulation marker
74-
* @param commentStart a char used for comment identification
75-
* @param escape a char used to escape special characters in values
76-
* @param leadingSpacesIgnored TRUE when leading whitespaces should be ignored
77-
* @param trailingSpacesIgnored TRUE when trailing whitespaces should be ignored
78-
* @param unicodeEscapesInterpreted TRUE when unicode escapes should be interpreted
79-
* @param emptyLinesIgnored TRUE when the parser should skip emtpy lines
79+
* @param delimiter the char used for value separation
80+
* @param encapsulator the char used as value encapsulation marker
81+
* @param commentStart the char used for comment identification
82+
* @param escape the char used to escape special characters in values
83+
* @param leadingSpacesIgnored <tt>true</tt> when leading whitespaces should be ignored
84+
* @param trailingSpacesIgnored <tt>true</tt> when trailing whitespaces should be ignored
85+
* @param unicodeEscapesInterpreted <tt>true</tt> when unicode escapes should be interpreted
86+
* @param emptyLinesIgnored <tt>true</tt> when the parser should skip emtpy lines
8087
*/
8188
public CSVFormat(
8289
char delimiter,

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,14 @@ public class CSVParser implements Iterable<String[]> {
6464
/** Immutable empty String array. */
6565
private static final String[] EMPTY_STRING_ARRAY = new String[0];
6666

67-
// the input stream
67+
/** The input stream */
6868
private final ExtendedBufferedReader in;
6969

7070
private final CSVFormat format;
7171

7272
// the following objects are shared to reduce garbage
73-
/**
74-
* A record buffer for getLine(). Grows as necessary and is reused.
75-
*/
73+
74+
/** A record buffer for getLine(). Grows as necessary and is reused. */
7675
private final List<String> record = new ArrayList<String>();
7776
private final Token reusableToken = new Token();
7877
private final CharBuffer wsBuf = new CharBuffer();
@@ -146,12 +145,10 @@ public CSVParser(Reader input, CSVFormat format) {
146145
// ======================================================
147146

148147
/**
149-
* Parses the CSV according to the given format
150-
* and returns the content as an array of records
151-
* (whereas records are arrays of single values).
148+
* Parses the CSV according to the given format and returns the content
149+
* as an array of records (whereas records are arrays of single values).
152150
* <p/>
153-
* The returned content starts at the current parse-position in
154-
* the stream.
151+
* The returned content starts at the current parse-position in the stream.
155152
*
156153
* @return matrix of records x values ('null' when end of file)
157154
* @throws IOException on parse error or input read-failure
@@ -171,11 +168,9 @@ public String[][] getRecords() throws IOException {
171168
}
172169

173170
/**
174-
* Parses from the current point in the stream til
175-
* the end of the current line.
171+
* Parses from the current point in the stream til * the end of the current line.
176172
*
177-
* @return array of values til end of line
178-
* ('null' when end of file has been reached)
173+
* @return array of values til end of line ('null' when end of file has been reached)
179174
* @throws IOException on parse error or input read-failure
180175
*/
181176
String[] getLine() throws IOException {
@@ -209,7 +204,7 @@ String[] getLine() throws IOException {
209204
}
210205
}
211206
if (!record.isEmpty()) {
212-
ret = (String[]) record.toArray(new String[record.size()]);
207+
ret = record.toArray(new String[record.size()]);
213208
}
214209
return ret;
215210
}
@@ -283,11 +278,9 @@ Token nextToken() throws IOException {
283278
/**
284279
* Returns the next token.
285280
* <p/>
286-
* A token corresponds to a term, a record change or an
287-
* end-of-file indicator.
281+
* A token corresponds to a term, a record change or an end-of-file indicator.
288282
*
289-
* @param tkn an existing Token object to reuse. The caller is responsible to initialize the
290-
* Token.
283+
* @param tkn an existing Token object to reuse. The caller is responsible to initialize the Token.
291284
* @return the next token found
292285
* @throws IOException on stream access error
293286
*/
@@ -380,9 +373,9 @@ Token nextToken(Token tkn) throws IOException {
380373
* A simple token might contain escaped delimiters (as \, or \;). The
381374
* token is finished when one of the following conditions become true:
382375
* <ul>
383-
* <li>end of line has been reached (EORECORD)</li>
384-
* <li>end of stream has been reached (EOF)</li>
385-
* <li>an unescaped delimiter has been reached (TOKEN)</li>
376+
* <li>end of line has been reached (EORECORD)</li>
377+
* <li>end of stream has been reached (EOF)</li>
378+
* <li>an unescaped delimiter has been reached (TOKEN)</li>
386379
* </ul>
387380
*
388381
* @param tkn the current token
@@ -476,19 +469,13 @@ private Token encapsulatedTokenLexer(Token tkn, int c) throws IOException {
476469
return tkn;
477470
} else if (!isWhitespace(c)) {
478471
// error invalid char between token and next delimiter
479-
throw new IOException(
480-
"(line " + getLineNumber()
481-
+ ") invalid char between encapsulated token end delimiter"
482-
);
472+
throw new IOException("(line " + getLineNumber() + ") invalid char between encapsulated token and delimiter");
483473
}
484474
}
485475
}
486476
} else if (isEndOfFile(c)) {
487477
// error condition (end of file before end of token)
488-
throw new IOException(
489-
"(startline " + startLineNumber + ")"
490-
+ "eof reached before encapsulated token finished"
491-
);
478+
throw new IOException("(startline " + startLineNumber + ") EOF reached before encapsulated token finished");
492479
} else {
493480
// consume character
494481
tkn.content.append((char) c);
@@ -500,8 +487,7 @@ private Token encapsulatedTokenLexer(Token tkn, int c) throws IOException {
500487
/**
501488
* Decodes Unicode escapes.
502489
* <p/>
503-
* Interpretation of "\\uXXXX" escape sequences
504-
* where XXXX is a hex-number.
490+
* Interpretation of "\\uXXXX" escape sequences where XXXX is a hex-number.
505491
*
506492
* @param c current char which is discarded because it's the "\\" of "\\uXXXX"
507493
* @return the decoded character
@@ -555,10 +541,6 @@ private int readEscape(int c) throws IOException {
555541
return out;
556542
}
557543

558-
// ======================================================
559-
// strategies
560-
// ======================================================
561-
562544
/**
563545
* Obtain the specified CSV format.
564546
*

src/main/java/org/apache/commons/csv/package.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ <h3>Apache Commons CSV Format Support</h3>
3535
record := values*
3636
</pre>
3737

38-
<p>The following list contains the csv aspects the WAKE CSV parser supports:</p>
38+
<p>The following list contains the csv aspects the Commons CSV parser supports:</p>
3939
<dl>
4040
<dt>Separators (for lines)</dt>
4141
<dd>The record separators are hardcoded and cannot be changed. The must be '\n' or '\r\n'.</dd>
@@ -76,9 +76,11 @@ <h3>Apache Commons CSV Format Support</h3>
7676

7777
<p>Example usage:</p>
7878
<blockquote><pre>
79-
String[] parsedLine = CSVParser.parseLine("a,b,c");
80-
for (int i = 0; i &lt; parsedLine.length; ++i) {
81-
System.out.println("value " + i + "=" + parsedLine[i]);
79+
Reader in = new StringReader("a,b,c");
80+
for (String[] line : CSVFormat.DEFAULT.parse(in)) {
81+
for (int i = 0; i &lt; line.length; i++) {
82+
System.out.println("value " + i + "=" + line[i]);
83+
}
8284
}
8385
</pre></blockquote>
8486
</body>

0 commit comments

Comments
 (0)