|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * Apache Commons CSV Format Support. |
| 21 | + * |
| 22 | + * <p>CSV (or its dialects) are widely used as interfaces to legacy systems or |
| 23 | + * manual data-imports. Basically CSV stands for "Comma Separated Values" but |
| 24 | + * this simple abbreviation leads to more confusion than definitions.</p> |
| 25 | + * |
| 26 | + * <p>Common to all file dialects is its basic structure: The CSV data-format |
| 27 | + * is record oriented, whereas each record starts on a new textual line. A |
| 28 | + * record is build of a list of values. Keep in mind that not all records |
| 29 | + * must have an equal number of values:</p> |
| 30 | + * <pre> |
| 31 | + * csv := records* |
| 32 | + * record := values* |
| 33 | + * </pre> |
| 34 | + * |
| 35 | + * <p>The following list contains the csv aspects the Commons CSV parser supports:</p> |
| 36 | + * <dl> |
| 37 | + * <dt>Separators (for lines)</dt> |
| 38 | + * <dd>The record separators are hardcoded and cannot be changed. The must be '\r', '\n' or '\r\n'.</dd> |
| 39 | + * |
| 40 | + * <dt>Delimiter (for values)</dt> |
| 41 | + * <dd>The delimiter for values is freely configurable (default ',').</dd> |
| 42 | + * |
| 43 | + * <dt>Comments</dt> |
| 44 | + * <dd>Some CSV-dialects support a simple comment syntax. A comment is a record |
| 45 | + * which must start with a designated character (the commentStarter). A record |
| 46 | + * of this kind is treated as comment and gets removed from the input (default none)</dd> |
| 47 | + * |
| 48 | + * <dt>Encapsulator</dt> |
| 49 | + * <dd>Two encapsulator characters (default '"') are used to enclose -> complex values.</dd> |
| 50 | + * |
| 51 | + * <dt>Simple values</dt> |
| 52 | + * <dd>A simple value consist of all characters (except the delimiter) until |
| 53 | + * (but not including) the next delimiter or a record-terminator. Optionally |
| 54 | + * all surrounding whitespaces of a simple value can be ignored (default: true).</dd> |
| 55 | + * |
| 56 | + * <dt>Complex values</dt> |
| 57 | + * <dd>Complex values are encapsulated within a pair of the defined encapsulator characters. |
| 58 | + * The encapsulator itself must be escaped or doubled when used inside complex values. |
| 59 | + * Complex values preserve all kind of formatting (including newlines -> multiline-values)</dd> |
| 60 | + * |
| 61 | + * <dt>Empty line skipping</dt> |
| 62 | + * <dd>Optionally empty lines in CSV files can be skipped. |
| 63 | + * Otherwise, empty lines will return a record with a single empty value.</dd> |
| 64 | + * </dl> |
| 65 | + * |
| 66 | + * <p>In addition to individually defined dialects, two predefined dialects (strict-csv, and excel-csv) |
| 67 | + * can be set directly.</p> <!-- TODO fix --> |
| 68 | + * |
| 69 | + * <p>Example usage:</p> |
| 70 | + * <blockquote><pre> |
| 71 | + * Reader in = new StringReader("a,b,c"); |
| 72 | + * for (CSVRecord record : CSVFormat.DEFAULT.parse(in)) { |
| 73 | + * for (int i = 0; i < record.length; i++) { |
| 74 | + * System.out.println("value " + i + "=" + record.get(i)); |
| 75 | + * } |
| 76 | + * } |
| 77 | + * </pre></blockquote> |
| 78 | + */ |
| 79 | + |
| 80 | +package org.apache.commons.csv; |
0 commit comments