Package com.atlan.samples.writers
Class CSVWriter
- java.lang.Object
-
- com.atlan.samples.writers.CSVWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class CSVWriter extends java.lang.Object implements java.io.Closeable
Utility class for creating and writing to CSV files, using FastCSV.
-
-
Constructor Summary
Constructors Constructor Description CSVWriter(java.lang.String path)
Construct a new CSV file writer, using a comma (as the C in CSV implies) as the field separator.CSVWriter(java.lang.String path, char fieldSeparator)
Construct a new CSV file writer, using a specific field separator character.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
streamAssets(java.util.stream.Stream<com.atlan.model.assets.Asset> stream, RowGenerator valuesForRow, long totalAssetCount, int pageSize)
Parallel-write the provided asset stream into the CSV file.void
writeHeader(java.lang.Iterable<java.lang.String> values)
Write a header row into the CSV file.
-
-
-
Constructor Detail
-
CSVWriter
public CSVWriter(java.lang.String path) throws java.io.IOException
Construct a new CSV file writer, using a comma (as the C in CSV implies) as the field separator.- Parameters:
path
- location and filename of the CSV file to produce- Throws:
java.io.IOException
- on any errors creating or accessing the file
-
CSVWriter
public CSVWriter(java.lang.String path, char fieldSeparator) throws java.io.IOException
Construct a new CSV file writer, using a specific field separator character.- Parameters:
path
- location and filename of the CSV file to producefieldSeparator
- character to use to separate fields (for example ',' or ';')- Throws:
java.io.IOException
- on any errors creating or accessing the file
-
-
Method Detail
-
writeHeader
public void writeHeader(java.lang.Iterable<java.lang.String> values)
Write a header row into the CSV file.- Parameters:
values
- to use for the header
-
streamAssets
public void streamAssets(java.util.stream.Stream<com.atlan.model.assets.Asset> stream, RowGenerator valuesForRow, long totalAssetCount, int pageSize)
Parallel-write the provided asset stream into the CSV file. (For the highest performance, we recommend sending in a parallel stream of assets.)- Parameters:
stream
- of assets, typically from a FluentSearch (parallel stream recommended)valuesForRow
- a function (could just be a lambda) that turns a single Asset into an iterable of String valuestotalAssetCount
- the total number of assets that will be output (used for logging / completion tracking)pageSize
- the page size being used by the asset stream
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-