java.lang.Object
io.github.astrapisixtynine.csv.CsvFileExtensions

public final class CsvFileExtensions extends Object
Utility class for the use of cvs-files.
  • Methodendetails

    • formatKommaSeperatedFileToList

      public static List<String> formatKommaSeperatedFileToList(File input, String encoding) throws IOException
      Reads every line from the File splits the data through a comma and puts them to the List.
      Parameter:
      input - The File from where the input comes.
      encoding - The encoding from the file.
      Gibt zurück:
      The List with all lines from the file.
      Löst aus:
      IOException - Signals that an I/O exception has occurred.
    • formatToCSV

      public static void formatToCSV(File input, File output, String encoding) throws IOException
      Formats a file that has in every line one input-data into a csv-file.
      Parameter:
      input - The input-file to format. The current format from the file is every data in a line.
      output - The file where the formatted data should be inserted.
      encoding - the encoding
      Löst aus:
      IOException - When an io error occurs.
    • getCvsAsListMap

      public static List<Map<String,String>> getCvsAsListMap(File input) throws IOException
      Gets the given cvs file as list of maps. Every map has as key the header from the column and the corresponding value for this line.
      Parameter:
      input - the input
      Gibt zurück:
      the cvs as list map
      Löst aus:
      IOException - Signals that an I/O exception has occurred.
    • getCvsAsListMap

      public static List<Map<String,String>> getCvsAsListMap(File input, String encoding) throws IOException
      Gets the given cvs file as list of maps. Every map has as key the header from the column and the corresponding value for this line.
      Parameter:
      input - the input
      encoding - the encoding to read
      Gibt zurück:
      the cvs as list map
      Löst aus:
      IOException - Signals that an I/O exception has occurred.
    • getDataFromLine

      public static String[] getDataFromLine(String line, String seperator)
      Gets the data from line.
      Parameter:
      line - the line
      seperator - the seperator
      Gibt zurück:
      the data from line
    • getDataFromLine

      public static String[] getDataFromLine(String line, String seperator, boolean trim)
      Gets the data from line.
      Parameter:
      line - the line
      seperator - the seperator
      trim - the trim
      Gibt zurück:
      the data from line
    • getLineCountFromCsvFile

      public static int getLineCountFromCsvFile(File file) throws IOException
      Gets the line count from csv file.
      Parameter:
      file - the file
      Gibt zurück:
      the line count from csv file
      Löst aus:
      IOException - Signals that an I/O exception has occurred.
    • readDataFromCVSFileToList

      public static List<String> readDataFromCVSFileToList(File input, int position, boolean putFirstLine, String encoding) throws IOException
      Reads from a csv-file the field from the given position and puts them to the List.
      Parameter:
      input - The input-file.
      position - The position from the field.
      putFirstLine - Flag that tells if the first line will be put in the list.
      encoding - the encoding
      Gibt zurück:
      The list with the data.
      Löst aus:
      IOException - When a io-problem occurs.
    • readDataFromCVSFileToList

      public static List<String> readDataFromCVSFileToList(File input, int position, boolean putFirstLine, String splitChar, String encoding) throws IOException
      Reads from a csv-file the field from the given position and puts them to the List.
      Parameter:
      input - The input-file.
      position - The position from the field.
      putFirstLine - Flag that tells if the first line will be put in the list.
      splitChar - the split char
      encoding - the encoding
      Gibt zurück:
      The list with the data.
      Löst aus:
      IOException - When a io-problem occurs.
    • readFilelistToProperties

      public static Properties readFilelistToProperties(File input) throws IOException
      Read filelist to properties.
      Parameter:
      input - the input
      Gibt zurück:
      the properties
      Löst aus:
      IOException - Signals that an I/O exception has occurred.
    • readFileToList

      public static List<String> readFileToList(File file) throws IOException
      Reads every line from the given File into a List and returns the List.
      Parameter:
      file - The file from where to read.
      Gibt zurück:
      The List with all lines from the File.
      Löst aus:
      IOException - When a io-problem occurs.
    • readFileToList

      public static List<String> readFileToList(File file, String encoding) throws IOException
      Reads every line from the given File into a List and returns the List.
      Parameter:
      file - The file from where to read.
      encoding - The encoding to read.
      Gibt zurück:
      The List with all lines from the File.
      Löst aus:
      IOException - When a io-problem occurs.
    • readFileToList

      public static List<String[]> readFileToList(File file, String seperator, String encoding) throws IOException
      Reads every line from the given File into a List of String arrays and returns the List.
      Parameter:
      file - The file from where to read.
      seperator - the seperator
      encoding - The encoding to read.
      Gibt zurück:
      The List with all lines from the File.
      Löst aus:
      IOException - Signals that an I/O exception has occurred.
    • readLinesInList

      public static List<String> readLinesInList(File input, String encoding) throws IOException
      Reads every line from the File and puts them to the List.
      Parameter:
      input - The File from where the input comes.
      encoding - The encoding from the file.
      Gibt zurück:
      The List with all lines from the file.
      Löst aus:
      IOException - When a io-problem occurs.
    • sortData

      public static String[] sortData(File csvData, String encoding) throws FileNotFoundException, IOException
      Read an csv-file and puts them in a String-array.
      Parameter:
      csvData - The csv-file with the data.
      encoding - The encoding to read.
      Gibt zurück:
      The data from the csv-file as a String-array.
      Löst aus:
      FileNotFoundException - is thrown if the given file is not found
      IOException - When an io-error occurs.
    • storeFilelistToProperties

      public static void storeFilelistToProperties(File output, File input, String comments) throws IOException
      Stores a komma seperated file to a properties object. As key is the number from the counter.
      Parameter:
      output - the output
      input - the input
      comments - the comments
      Löst aus:
      IOException - Signals that an I/O exception has occurred.
    • writeLines

      public static void writeLines(File output, Set<String> values, String encoding) throws IOException
      Writes the toString() value of each item in a collection to the specified File line by line. The default VM encoding and the default line ending will be used.
      Parameter:
      output - The File where the values to save.
      values - The Set with the values to put into the file.
      encoding - The encoding from the file.
      Löst aus:
      IOException - When a io-problem occurs.
    • writeLinesToFile

      public static void writeLinesToFile(Collection<String> collection, File output, String encoding) throws IOException
      Writes all the String-object in the collection into the given file.
      Parameter:
      collection - The collection with the String-object.
      output - The file where the String-object will be writing.
      encoding - The encoding from the file.
      Löst aus:
      IOException - Signals that an I/O exception has occurred.