Skip to content

Commit

Permalink
improve doc
Browse files Browse the repository at this point in the history
  • Loading branch information
osiegmar committed Jan 4, 2024
1 parent 2cfff17 commit aa5ed36
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package example;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;

import de.siegmar.fastcsv.reader.CsvReader;
import de.siegmar.fastcsv.reader.CsvRecord;

/**
* Example for reading CSV data from a file in the classpath.
*/
public class ExampleCsvReaderWithClasspathInput {

public static void main(final String[] args) throws IOException {
try (CsvReader<CsvRecord> csv = CsvReader.builder().build(getReader("/example.csv"))) {
for (final CsvRecord csvRecord : csv) {
System.out.println(csvRecord.getFields());
}
}
}

private static Reader getReader(final String name) {
final InputStream in = ExampleCsvReaderWithClasspathInput.class.getResourceAsStream(name);
if (in == null) {
throw new IllegalStateException("Resource not found: " + name);
}
return new InputStreamReader(in, StandardCharsets.UTF_8);
}

}
11 changes: 10 additions & 1 deletion lib/src/main/java/de/siegmar/fastcsv/reader/CsvReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,16 @@ public void close() throws IOException {

/**
* This builder is used to create configured instances of {@link CsvReader}. The default
* configuration of this class complies with RFC 4180.
* configuration of this class complies with RFC 4180:
* <ul>
* <li>Field separator: {@code ,} (comma)</li>
* <li>Quote character: {@code "} (double quotes)</li>
* <li>Comment strategy: {@link CommentStrategy#NONE} (as RFC doesn't handle comments)</li>
* <li>Comment character: {@code #} (hash) (in case comment strategy is enabled)</li>
* <li>Skip empty lines: {@code true}</li>
* <li>Ignore different field count: {@code true}</li>
* <li>Detect BOM header: {@code false}</li>
* </ul>
* <p>
* The line delimiter (line-feed, carriage-return or the combination of both) is detected
* automatically and thus not configurable.
Expand Down
8 changes: 8 additions & 0 deletions lib/src/main/java/de/siegmar/fastcsv/writer/CsvWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ public String toString() {
/**
* This builder is used to create configured instances of {@link CsvWriter}. The default
* configuration of this class complies with RFC 4180.
* <ul>
* <li>field separator: {@code ,} (comma)</li>
* <li>quote character: {@code "} (double quote)</li>
* <li>comment character: {@code #} (hash/number)</li>
* <li>quote strategy: {@code null} (only required quoting)</li>
* <li>line delimiter: {@link LineDelimiter#CRLF}</li>
* <li>buffer size: 8,192 bytes</li>
* </ul>
*/
@SuppressWarnings({"checkstyle:HiddenField", "PMD.AvoidFieldNameMatchingMethodName"})
public static final class CsvWriterBuilder {
Expand Down

0 comments on commit aa5ed36

Please sign in to comment.