Package org.gbif.utils.file.tabular
Class TabularFileNormalizer
java.lang.Object
org.gbif.utils.file.tabular.TabularFileNormalizer
Utility class to rewrite a tabular file (e.g. CSV) into a normalized format.
The regular use case is to allow external tools to work as expected (e.g. unix split, unix sort).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
NORMALIZED_END_OF_LINE
- See Also:
-
-
Constructor Details
-
TabularFileNormalizer
public TabularFileNormalizer()
-
-
Method Details
-
normalizeFile
public static int normalizeFile(Path source, Path destination, Charset sourceCharset, char delimiterChar, String endOfLineSymbols, Character quoteChar) throws IOException Normalizes the provided tabular "file" (provided asReaderto let the caller deal with charset). Normalization includes: stripping of Control Characters (seeCONTROL_CHAR_REGEX), usage of \n as end-line-character, ensuring there is an end-of-line character on the last line and removing empty (completely empty) lines. The normalized content will have unnecessary quotes removed.- Parameters:
source-Pathrepresenting the sourcedestination-Pathrepresenting the destination. If the file already exists it will be overwritten.sourceCharset- optionally, theCharsetof the source. If null UTF-8 will be used.delimiterChar-endOfLineSymbols-quoteChar- optional- Returns:
- number of lines written
- Throws:
IOException
-