3737
3838/**
3939 * Parses CSV files according to the specified configuration.
40- *
40+ *
4141 * Because CSV appears in many different dialects, the parser supports many configuration settings by allowing the
4242 * specification of a {@link CSVFormat}.
43- *
43+ *
4444 * <p>
4545 * To parse a CSV input with tabs as separators, '"' (double-quote) as an optional value encapsulator, and comments
4646 * starting with '#', you write:
4747 * </p>
48- *
48+ *
4949 * <pre>
5050 * Reader in = new StringReader("a\tb\nc\td");
5151 * Iterable<CSVRecord> parser = CSVFormat.DEFAULT
5656 * ...
5757 * }
5858 * </pre>
59- *
59+ *
6060 * <p>
6161 * To parse CSV input in a given format like Excel, you write:
6262 * </p>
63- *
63+ *
6464 * <pre>
6565 * Reader in = new StringReader("a;b\nc;d");
6666 * Iterable<CSVRecord> parser = CSVFormat.EXCEL.parse(in);
7171 * <p>
7272 * You may also get a List of records:
7373 * </p>
74- *
74+ *
7575 * <pre>
7676 * Reader in = new StringReader("a;b\nc;d");
7777 * CSVParser parser = new CSVParser(in, CSVFormat.EXCEL);
8383 * <p>
8484 * Internal parser state is completely covered by the format and the reader-state.
8585 * </p>
86- *
86+ *
8787 * <p>
8888 * see <a href="package-summary.html">package documentation</a> for more details
8989 * </p>
90- *
90+ *
9191 * @version $Id$
9292 */
9393public class CSVParser implements Iterable <CSVRecord >, Closeable {
9494
9595 /**
9696 * Creates a parser for the given {@link File}.
97- *
97+ *
9898 * @param file
9999 * a CSV file
100100 * @param format
@@ -109,11 +109,11 @@ public static CSVParser parseFile(File file, final CSVFormat format) throws IOEx
109109
110110 /**
111111 * Creates a parser for the given resource.
112- *
112+ *
113113 * <p>
114114 * If you do not read all records from the given source, you should call {@link #close()} on the parser.
115115 * </p>
116- *
116+ *
117117 * @param resource
118118 * a resource path
119119 * @param charset
@@ -128,7 +128,7 @@ public static CSVParser parseFile(File file, final CSVFormat format) throws IOEx
128128 */
129129 public static CSVParser parseResource (String resource , Charset charset , ClassLoader classLoader ,
130130 final CSVFormat format ) throws IOException {
131- URL url = classLoader .getResource (resource );
131+ final URL url = classLoader .getResource (resource );
132132 if (url == null ) {
133133 throw new IllegalArgumentException ("Resource cannot be found: " + resource );
134134 }
@@ -137,11 +137,11 @@ public static CSVParser parseResource(String resource, Charset charset, ClassLoa
137137
138138 /**
139139 * Creates a parser for the given resource.
140- *
140+ *
141141 * <p>
142142 * If you do not read all records from the given source, you should call {@link #close()} on the parser.
143143 * </p>
144- *
144+ *
145145 * @param resource
146146 * a resource path
147147 * @param charset
@@ -153,7 +153,7 @@ public static CSVParser parseResource(String resource, Charset charset, ClassLoa
153153 * If an I/O error occurs
154154 */
155155 public static CSVParser parseResource (String resource , Charset charset , final CSVFormat format ) throws IOException {
156- URL url = ClassLoader .getSystemResource (resource );
156+ final URL url = ClassLoader .getSystemResource (resource );
157157 if (url == null ) {
158158 throw new IllegalArgumentException ("System resource cannot be found: " + resource );
159159 }
@@ -162,7 +162,7 @@ public static CSVParser parseResource(String resource, Charset charset, final CS
162162
163163 /**
164164 * Creates a parser for the given {@link String} using the default format {@link CSVFormat#DEFAULT}.
165- *
165+ *
166166 * @param string
167167 * a CSV string
168168 * @return a new parser
@@ -175,7 +175,7 @@ public static CSVParser parseString(String string) throws IOException {
175175
176176 /**
177177 * Creates a parser for the given {@link String}.
178- *
178+ *
179179 * @param string
180180 * a CSV string
181181 * @param format
@@ -190,12 +190,12 @@ public static CSVParser parseString(String string, final CSVFormat format) throw
190190
191191 /**
192192 * Creates a parser for the given URL.
193- *
193+ *
194194 * <p>
195195 * If you do not read all records from the given {@code url}, you should call {@link #close()} on the parser, unless
196196 * you close the {@code url}.
197197 * </p>
198- *
198+ *
199199 * @param url
200200 * a URL
201201 * @param charset
@@ -230,12 +230,12 @@ public static CSVParser parseURL(URL url, Charset charset, final CSVFormat forma
230230
231231 /**
232232 * CSV parser using the default format {@link CSVFormat#DEFAULT}.
233- *
233+ *
234234 * <p>
235235 * If you do not read all records from the given {@code reader}, you should call {@link #close()} on the parser,
236236 * unless you close the {@code reader}.
237237 * </p>
238- *
238+ *
239239 * @param input
240240 * a Reader containing "csv-formatted" input
241241 * @throws IllegalArgumentException
@@ -249,12 +249,12 @@ public CSVParser(final Reader input) throws IOException {
249249
250250 /**
251251 * Customized CSV parser using the given {@link CSVFormat}
252- *
252+ *
253253 * <p>
254254 * If you do not read all records from the given {@code reader}, you should call {@link #close()} on the parser,
255255 * unless you close the {@code reader}.
256256 * </p>
257- *
257+ *
258258 * @param reader
259259 * a Reader containing CSV-formatted input
260260 * @param format
@@ -283,7 +283,7 @@ private void addRecordValue() {
283283
284284 /**
285285 * Closes resources.
286- *
286+ *
287287 * @throws IOException
288288 * If an I/O error occurs
289289 */
@@ -297,7 +297,7 @@ public void close() throws IOException {
297297 * Returns the current line number in the input stream.
298298 * <p/>
299299 * ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to the record number.
300- *
300+ *
301301 * @return current line number
302302 */
303303 public long getCurrentLineNumber () {
@@ -308,7 +308,7 @@ public long getCurrentLineNumber() {
308308 * Returns a copy of the header map that iterates in column order.
309309 * <p>
310310 * The map keys are column names. The map values are 0-based indices.
311- *
311+ *
312312 * @return a copy of the header map that iterates in column order.
313313 */
314314 public Map <String , Integer > getHeaderMap () {
@@ -319,7 +319,7 @@ public Map<String, Integer> getHeaderMap() {
319319 * Returns the current record number in the input stream.
320320 * <p/>
321321 * ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to the line number.
322- *
322+ *
323323 * @return current line number
324324 */
325325 public long getRecordNumber () {
@@ -331,7 +331,7 @@ public long getRecordNumber() {
331331 * entries.
332332 * <p/>
333333 * The returned content starts at the current parse-position in the stream.
334- *
334+ *
335335 * @return list of {@link CSVRecord} entries, may be empty
336336 * @throws IOException
337337 * on parse error or input read-failure
@@ -350,7 +350,7 @@ public List<CSVRecord> getRecords() throws IOException {
350350 */
351351 private Map <String , Integer > initializeHeader () throws IOException {
352352 Map <String , Integer > hdrMap = null ;
353- String [] formatHeader = this .format .getHeader ();
353+ final String [] formatHeader = this .format .getHeader ();
354354 if (formatHeader != null ) {
355355 hdrMap = new LinkedHashMap <String , Integer >();
356356
@@ -436,7 +436,7 @@ public void remove() {
436436
437437 /**
438438 * Parses the next record from the current point in the stream.
439- *
439+ *
440440 * @return the record as an array of values, or <tt>null</tt> if the end of the stream has been reached
441441 * @throws IOException
442442 * on parse error or input read-failure
0 commit comments