Package io.github.astrapisixtynine.csv
Klasse CsvExtensions
java.lang.Object
io.github.astrapisixtynine.csv.CsvExtensions
The
CsvExtensions
class provides utility methods to read data from CSV files, map the
data to objects, and generate maps of data from lists of objects. This class supports reading CSV
files using Apache Commons CSV and creating data structures like lists and maps from the parsed
CSV data-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic <T> List
<T> readEntriesFromCsv
(File csvFile, Function<org.apache.commons.csv.CSVRecord, T> recordMapper) Reads entries from a CSV file, processes each record using a provided mapper function, and returns a list of mapped entriesstatic <T> List
<T> readEntriesFromCsv
(InputStream csvInputStream, Function<org.apache.commons.csv.CSVRecord, T> recordMapper) Reads entries from a CSV input stream, processes each record using a provided mapper function, and returns a list of mapped entriesstatic void
sortCsv
(Path csvFilePath, Supplier<Comparator<String[]>> comparatorSupplier) Reads a CSV file, sorts its data based on a supplied comparator, and writes the sorted data back to the file.static void
sortCsvByAlgorithmAndKeysize
(Path csvFilePath) Reads a CSV file, sorts its data by 'algorithm' and 'keysize' in ascending order, and writes the sorted data back to the filestatic void
sortCsvByKeypairAndSignatureAlgorithm
(Path csvFilePath) Sorts a CSV file by 'keypair-algorithm' and 'signature-algorithm', removes duplicates, and rewrites the sorted data back to the CSV file
-
Methodendetails
-
sortCsvByKeypairAndSignatureAlgorithm
Sorts a CSV file by 'keypair-algorithm' and 'signature-algorithm', removes duplicates, and rewrites the sorted data back to the CSV file- Parameter:
csvFilePath
- the path to the CSV file to be sorted- Löst aus:
IOException
- if an I/O error occurs
-
sortCsv
public static void sortCsv(Path csvFilePath, Supplier<Comparator<String[]>> comparatorSupplier) throws IOException Reads a CSV file, sorts its data based on a supplied comparator, and writes the sorted data back to the file.- Parameter:
csvFilePath
- the path to the CSV file to be sortedcomparatorSupplier
- a supplier that provides a comparator for sorting the rows- Löst aus:
IOException
- if an I/O error occurs
-
sortCsvByAlgorithmAndKeysize
Reads a CSV file, sorts its data by 'algorithm' and 'keysize' in ascending order, and writes the sorted data back to the file- Parameter:
csvFilePath
- the path to the CSV file to be sorted- Löst aus:
IOException
- if an I/O error occurs
-
readEntriesFromCsv
public static <T> List<T> readEntriesFromCsv(InputStream csvInputStream, Function<org.apache.commons.csv.CSVRecord, T> recordMapper) throws IOExceptionReads entries from a CSV input stream, processes each record using a provided mapper function, and returns a list of mapped entries- Typparameter:
T
- the generic type of the returned entries- Parameter:
csvInputStream
- the input stream of the CSV filerecordMapper
- a function that maps each CSV record to an object of type T- Gibt zurück:
- a list of mapped entries of type T
- Löst aus:
IOException
- if an I/O error occurs
-
readEntriesFromCsv
public static <T> List<T> readEntriesFromCsv(File csvFile, Function<org.apache.commons.csv.CSVRecord, T> recordMapper) throws IOExceptionReads entries from a CSV file, processes each record using a provided mapper function, and returns a list of mapped entries- Typparameter:
T
- the generic type of the returned entries- Parameter:
csvFile
- the CSV file to read fromrecordMapper
- a function that maps each CSV record to an object of type T- Gibt zurück:
- a list of mapped entries of type T
- Löst aus:
IOException
- if an I/O error occurs
-