Class TabularFileNormalizer

java.lang.Object
org.gbif.utils.file.tabular.TabularFileNormalizer

public class TabularFileNormalizer extends Object
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 Details

  • Constructor Details

  • 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 as Reader to let the caller deal with charset). Normalization includes: stripping of Control Characters (see CONTROL_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 - Path representing the source
      destination - Path representing the destination. If the file already exists it will be overwritten.
      sourceCharset - optionally, the Charset of the source. If null UTF-8 will be used.
      delimiterChar -
      endOfLineSymbols -
      quoteChar - optional
      Returns:
      number of lines written
      Throws:
      IOException