Class InconsistentRowLengthException

  • All Implemented Interfaces:
    Serializable

    public final class InconsistentRowLengthException
    extends org.apache.metamodel.InconsistentRowFormatException
    Exception thrown when a line in a CSV file has an inconsistent amount of columns compared to the previous lines (and headers). The exception will be thrown when DataSet.next() is called. Note that this exception is only thrown if the CsvConfiguration.isFailOnInconsistentRowLength() property is true. Enabling it allows a somewhat different approach to iterating through a resulting DataSet. For example something like:
     while (true) {
            try {
                    if (!dataSet.next) {
                            break;
                    }
                    Row row = dataSet.getRow();
                    handleRegularRow(row);
            } catch (InconsistentRowLengthException e) {
                    handleIrregularRow(e.getSourceLine());
            }
     }
     
    See Also:
    Serialized Form
    • Constructor Detail

      • InconsistentRowLengthException

        public InconsistentRowLengthException​(int columnsInTable,
                                              org.apache.metamodel.data.Row proposedRow,
                                              String[] line,
                                              int rowNumber)
    • Method Detail

      • getMessage

        public String getMessage()
        Overrides:
        getMessage in class org.apache.metamodel.InconsistentRowFormatException
      • getSourceLine

        public String[] getSourceLine()
        Gets the source line, as parsed by the CSV parser (regardless of table metadata).
        Returns:
        an array of string values.
      • getColumnsInLine

        public int getColumnsInLine()
        Gets the amount of columns in the parsed line.
        Returns:
        an int representing the amount of values in the inconsistent line.
      • getColumnsInTable

        public int getColumnsInTable()
        Gets the expected amounts of columns, as defined by the table metadata.
        Returns:
        an int representing the amount of columns defined in the table.