Module jonix

Class JonixDelimitedWriter<P>

java.lang.Object
com.tectonica.jonix.tabulate.JonixDelimitedWriter<P>
Type Parameters:
P - the type of the ONIX Products to be written
All Implemented Interfaces:
AutoCloseable

public class JonixDelimitedWriter<P> extends Object implements AutoCloseable
Class that facilitates writing a char-delimited file where each line contains one ONIX Product. The key for extracting flat list of values from an (tree-shaped) ONIX Product lies in the Tabulation object which must be provided to this class. The Tabulation object also has all the header-related information.

Typically, this class is not accessed directly (unless for subclassing). Refer to the helper functions, writeFile(File, char, Tabulation, Iterable) and writeFile(File, char, Tabulation, Stream), or alternatively, if using a stream of ONIX Products, consider the Collector returned by toDelimitedFile(File, char, Tabulation).

  • Field Details

    • out

      protected repackaged.com.csvreader.CsvWriter out
    • linesWritten

      protected int linesWritten
  • Constructor Details

    • JonixDelimitedWriter

      public JonixDelimitedWriter(File targetFile, Tabulation<P> tabulation)
    • JonixDelimitedWriter

      public JonixDelimitedWriter(File targetFile, char delimiter, Tabulation<P> tabulation)
  • Method Details

    • initializeWriter

      protected void initializeWriter(File targetFile, char delimiter)
    • writeHeader

      protected void writeHeader()
    • writeProduct

      protected void writeProduct(P product)
    • writeRow

      protected void writeRow(List<String> row)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getLinesWritten

      public int getLinesWritten()
    • toDelimitedFile

      public static <P> Collector<P,?,Integer> toDelimitedFile(File targetFile, char delimiter, Tabulation<P> tabulation)
      Returns a Collector for writing a stream of ONIX Products into a tab-separated file (with header)
      Type Parameters:
      P - the type of the ONIX Products contained in the stream
      Parameters:
      targetFile - the destination (char-delimited) file
      delimiter - the character to use as a delimiter in the output file, typically ','
      tabulation - a Tabulation object for to the type of the ONIX Products contained in the stream. this object has all the information needed to extract and flatten data from each product.
      Returns:
      a Collector to be used in conjunction with Stream.collect(Collector)
    • writeFile

      public static <P> void writeFile(File targetFile, char delimiter, Tabulation<P> tabulation, Stream<P> productsStream)
      Convenience method for writing a Stream of ONIX Products into a char-delimited file
      Type Parameters:
      P - the type of the ONIX Products contained in the iterable
      Parameters:
      targetFile - the destination (char-delimited) file
      delimiter - the character to use as a delimiter in the output file, typically ','
      tabulation - a Tabulation object for to the type of the ONIX Products contained in the stream. this object has all the information needed to extract and flatten data from each product.
      productsStream - Stream of ONIX Products
    • writeFile

      public static <P> void writeFile(File targetFile, char delimiter, Tabulation<P> tabulation, Iterable<P> products)
      Convenience method for writing an Iterable of ONIX Products into a char-delimited file
      Type Parameters:
      P - the type of the ONIX Products contained in the stream
      Parameters:
      targetFile - the destination (char-delimited) file
      delimiter - the character to use as a delimiter in the output file, typically ','
      tabulation - a Tabulation object for to the type of the ONIX Products contained in the iterable. this object has all the information needed to extract and flatten data from each product.
      products - an Iterable of ONIX Products