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
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 Summary
Modifier and TypeFieldDescriptionprotected int
protected repackaged.com.csvreader.CsvWriter
-
Constructor Summary
ConstructorDescriptionJonixDelimitedWriter
(File targetFile, char delimiter, Tabulation<P> tabulation) JonixDelimitedWriter
(File targetFile, Tabulation<P> tabulation) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
int
protected void
initializeWriter
(File targetFile, char delimiter) toDelimitedFile
(File targetFile, char delimiter, Tabulation<P> tabulation) Returns aCollector
for writing a stream of ONIX Products into a tab-separated file (with header)static <P> void
writeFile
(File targetFile, char delimiter, Tabulation<P> tabulation, Iterable<P> products) Convenience method for writing anIterable
of ONIX Products into a char-delimited filestatic <P> void
writeFile
(File targetFile, char delimiter, Tabulation<P> tabulation, Stream<P> productsStream) Convenience method for writing aStream
of ONIX Products into a char-delimited fileprotected void
protected void
writeProduct
(P product) protected void
-
Field Details
-
out
protected repackaged.com.csvreader.CsvWriter out -
linesWritten
protected int linesWritten
-
-
Constructor Details
-
JonixDelimitedWriter
-
JonixDelimitedWriter
-
-
Method Details
-
initializeWriter
-
writeHeader
protected void writeHeader() -
writeProduct
-
writeRow
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
getLinesWritten
public int getLinesWritten() -
toDelimitedFile
public static <P> Collector<P,?, toDelimitedFileInteger> (File targetFile, char delimiter, Tabulation<P> tabulation) Returns aCollector
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) filedelimiter
- the character to use as a delimiter in the output file, typically ','tabulation
- aTabulation
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 withStream.collect(Collector)
-
writeFile
public static <P> void writeFile(File targetFile, char delimiter, Tabulation<P> tabulation, Stream<P> productsStream) Convenience method for writing aStream
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) filedelimiter
- the character to use as a delimiter in the output file, typically ','tabulation
- aTabulation
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 anIterable
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) filedelimiter
- the character to use as a delimiter in the output file, typically ','tabulation
- aTabulation
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
- anIterable
of ONIX Products
-