|
35 | 35 |
|
36 | 36 | /** |
37 | 37 | * Specifies the format of a CSV file and parses input. |
| 38 | + * |
38 | 39 | * <h4>Using predefined formats</h4> |
| 40 | + * |
39 | 41 | * <p> |
40 | 42 | * You can use one of the predefined formats: |
41 | 43 | * </p> |
| 44 | + * |
42 | 45 | * <ul> |
43 | 46 | * <li>{@link #DEFAULT}</li> |
44 | 47 | * <li>{@link #EXCEL}</li> |
45 | 48 | * <li>{@link #MYSQL}</li> |
46 | 49 | * <li>{@link #RFC4180}</li> |
47 | 50 | * <li>{@link #TDF}</li> |
48 | 51 | * </ul> |
49 | | - * <p>For example:</p> |
50 | | - * <pre>CSVParser parser = CSVFormat.EXCEL.parse(reader);</pre> |
51 | | - * <p>The {@link CSVRecord} provides static methods to parse other input types, for example:</p> |
| 52 | + * |
| 53 | + * <p> |
| 54 | + * For example: |
| 55 | + * </p> |
| 56 | + * |
| 57 | + * <pre> |
| 58 | + * CSVParser parser = CSVFormat.EXCEL.parse(reader); |
| 59 | + * </pre> |
| 60 | + * |
| 61 | + * <p> |
| 62 | + * The {@link CSVRecord} provides static methods to parse other input types, for example: |
| 63 | + * </p> |
| 64 | + * |
52 | 65 | * <pre>CSVParser parser = CSVFormat.parseFile(file, CSVFormat.EXCEL);</pre> |
| 66 | + * |
53 | 67 | * <h4>Defining formats</h4> |
| 68 | + * |
54 | 69 | * <p> |
55 | 70 | * You can extend a format by calling the {@code with} methods. For example: |
56 | 71 | * </p> |
57 | | - * <pre>CSVFormat.EXCEL |
| 72 | + * |
| 73 | + * <pre> |
| 74 | + * CSVFormat.EXCEL |
58 | 75 | * .withNullString("N/A") |
59 | | - * .withIgnoreSurroundingSpaces(true);</pre> |
| 76 | + * .withIgnoreSurroundingSpaces(true); |
| 77 | + * </pre> |
| 78 | + * |
60 | 79 | * <h4>Defining column names</h4> |
| 80 | + * |
61 | 81 | * <p> |
62 | 82 | * To define the column names you want to use to access records, write: |
63 | 83 | * </p> |
64 | | - * <pre>CSVFormat.EXCEL.withHeader("Col1", "Col2", "Col3");</pre> |
| 84 | + * |
| 85 | + * <pre> |
| 86 | + * CSVFormat.EXCEL.withHeader("Col1", "Col2", "Col3"); |
| 87 | + * </pre> |
| 88 | + * |
65 | 89 | * <p> |
66 | 90 | * Calling {@link #withHeader(String...)} let's you use the given names to address values in a {@link CSVRecord}, and |
67 | | - * assumes that your CSV source does not contain a first record that also defines column names. If it does, then |
68 | | - * you are overriding this metadata with your names and you should skip the first record by calling |
| 91 | + * assumes that your CSV source does not contain a first record that also defines column names. |
| 92 | + * |
| 93 | + * If it does, then you are overriding this metadata with your names and you should skip the first record by calling |
69 | 94 | * {@link #withSkipHeaderRecord(boolean)} with {@code true}. |
70 | 95 | * </p> |
| 96 | + * |
71 | 97 | * <h4>Parsing</h4> |
| 98 | + * |
72 | 99 | * <p> |
73 | 100 | * You can use a format directly to parse a reader. For example, to parse an Excel file with columns header, write: |
74 | 101 | * </p> |
75 | | - * <pre>Reader in = ...; |
76 | | - *CSVFormat.EXCEL.withHeader("Col1", "Col2", "Col3").parse(in);</pre> |
| 102 | + * |
| 103 | + * <pre> |
| 104 | + * Reader in = ...; |
| 105 | + * CSVFormat.EXCEL.withHeader("Col1", "Col2", "Col3").parse(in); |
| 106 | + * </pre> |
| 107 | + * |
77 | 108 | * <p> |
78 | 109 | * For other input types, like resources, files, and URLs, use the static methods on {@link CSVParser}. |
79 | 110 | * </p> |
| 111 | + * |
80 | 112 | * <h4>Referencing columns safely</h4> |
| 113 | + * |
81 | 114 | * <p> |
82 | 115 | * If your source contains a header record, you can simplify your code and safely reference columns, |
83 | 116 | * by using {@link #withHeader(String...)} with no arguments: |
84 | 117 | * </p> |
85 | | - * <pre>CSVFormat.EXCEL.withHeader();</pre> |
| 118 | + * |
| 119 | + * <pre> |
| 120 | + * CSVFormat.EXCEL.withHeader(); |
| 121 | + * </pre> |
| 122 | + * |
86 | 123 | * <p> |
87 | 124 | * This causes the parser to read the first record and use its values as column names. |
| 125 | + * |
88 | 126 | * Then, call one of the {@link CSVRecord} get method that takes a String column name argument: |
89 | 127 | * </p> |
90 | | - * <pre>String value = record.get("Col1");</pre> |
| 128 | + * |
| 129 | + * <pre> |
| 130 | + * String value = record.get("Col1"); |
| 131 | + * </pre> |
| 132 | + * |
91 | 133 | * <p> |
92 | 134 | * This makes your code impervious to changes in column order in the CSV file. |
93 | 135 | * </p> |
| 136 | + * |
94 | 137 | * <h4>Notes</h4> |
| 138 | + * |
95 | 139 | * <p> |
96 | 140 | * This class is immutable. |
97 | 141 | * </p> |
| 142 | + * |
98 | 143 | * @version $Id$ |
99 | 144 | */ |
100 | 145 | public class CSVFormat implements Serializable { |
|
0 commit comments