Package org.supercsv.exception

Examples of org.supercsv.exception.SuperCsvException


  addValues(requiredHashcodes);
}

protected void addValues(final int... requiredHashcodes) throws SuperCSVException {
  for( final int hash : requiredHashcodes ) {
    if( requiredHashCodes.contains(hash) ) { throw new SuperCSVException("Cannot accept two identical hash codes",
      this); }
    requiredHashCodes.add(hash);
  }
}
View Full Code Here


    for( final int hash : requiredHashCodes ) {
      sb.append(hash + ", ");
    }
    sb.deleteCharAt(sb.length() - 1); // delete last comma
   
    throw new SuperCSVException("Entry \"" + value + "\" on line " + context.lineNumber + " column "
      + context.columnNumber + " has hashcode " + value.hashCode()
      + " which is not one of the required hash codes: " + sb.toString(), context, this);
  }
 
  return next.execute(value, context);
View Full Code Here

  if( value == null ) { throw new NullInputException("Input cannot be null on line " + context.lineNumber + " at column " + context.columnNumber, context, this); }
  final String sval = value.toString(); // cast
 
  // check for forbidden strings
  for( final String forbidden : forbiddenSubStrings ) {
    if( sval.indexOf(forbidden) != -1 ) { throw new SuperCSVException("Entry \"" + value + "\" on line "
      + context.lineNumber + " column " + context.columnNumber + " contains the forbidden char \"" + forbidden
      + "\"", context, this); }
  }
 
  return next.execute(value, context);
View Full Code Here

}

/** Ensure we only memorize valid lengths */
protected void addValues(final int... requiredLengths) throws SuperCSVException {
  for( final int length : requiredLengths ) {
    if( length < 0 ) { throw new SuperCSVException("Cannot accept length below 0", this); }
    this.requiredLengths.add(length);
  }
}
View Full Code Here

    + " at column " + context.columnNumber, context, this); }
  final String sval = (value == null) ? null : value.toString(); // cast
  final int slength = (sval == null) ? 0 : sval.length();
 
  // check for required lengths
  if( !requiredLengths.contains(slength) ) { throw new SuperCSVException("Entry \"" + value + "\" is not of any of "
    + "the required lengths " + printRequiredLengths(), context, this); }
 
  return next.execute(value, context);
}
View Full Code Here

  else {
    try {
      result = Long.parseLong(value.toString());
    }
    catch(final NumberFormatException e) {
      throw new SuperCSVException("Parsing error", context, this, e);
    }
  }
 
  if( !(result >= min && result <= max) ) {
    throw new SuperCSVException("Entry \"" + value + "\" on line " + context.lineNumber + " column "
      + context.columnNumber + " is not within the numerical range " + min + "-" + max, context, this);
  }
 
  return next.execute(result, context);
}
View Full Code Here

  return next.execute(result, context);
}

private void init(final long _min, final long _max) {
  if( _max < _min ) {
    throw new SuperCSVException("max < min in the arguments " + _min + " " + _max, this);
  }
 
  this.min = _min;
  this.max = _max;
}
View Full Code Here

* @return the argument value if the value is unique
*/
@Override
public Object execute(final Object value, final CSVContext context) throws SuperCSVException {
  if( previousEncounteredElements.contains(value) ) {
    throw new SuperCSVException("Duplicate entry \"" + value + "\" error", context, this);
  } else {
    previousEncounteredElements.add(value);
  }
 
  // chaining
View Full Code Here

         * spaces need quotes), add the character, then continue to next character.
         */
        isEscape = false;
        if( this.strictQuotes && espectQuote ) {

      throw new SuperCsvException(
                String.format(
                  "strictQuotes: quotes needed at line %d column %d. To proceed, " +
                  "either quote the column or remove --strictquotes",
                  getLineNumber(), columns.size() + 1));
        }
        if( !surroundingSpacesNeedQuotes || currentColumn.length() > 0 ) {
      appendSpaces(currentColumn, potentialSpaces);
        }

        potentialSpaces = 0;
        currentColumn.append(c);
    }
    else if( c == escapeChar && !(line.charAt(charIndex+1) == 'N') ) {
        isEscape = true;
    }

    else if( c == delimeterChar ) {
        /*
         * Delimiter. Save the column (trim trailing space if required) then continue to next character.
         */
        espectQuote = true;
        if( !surroundingSpacesNeedQuotes ) {
      appendSpaces(currentColumn, potentialSpaces);
        }
        columns.add(currentColumn.length() > 0 ? currentColumn.toString() : null); // "" -> null
        potentialSpaces = 0;
        currentColumn.setLength(0);

    } else if( c == SPACE ) {
        /*
         * Space. Remember it, then continue to next character.
         */
        potentialSpaces++;

    } else if( c == NEWLINE ) {
        /*
         * Newline. Add any required spaces (if surrounding spaces don't need quotes) and return (we've read
         * a line!).
         */
        if( !surroundingSpacesNeedQuotes ) {
      appendSpaces(currentColumn, potentialSpaces);
        }
        columns.add(currentColumn.length() > 0 ? currentColumn.toString() : null); // "" -> null
        return true;

    } else if( c == quoteChar ) {
        /*
         * A single quote ("). Update to QUOTESCOPE (but don't save quote), then continue to next character.
         */
        espectQuote = false;
        state = TokenizerState.QUOTE_MODE;
        quoteScopeStartingLine = getLineNumber();

        // cater for spaces before a quoted section (be lenient!)
        if( !surroundingSpacesNeedQuotes || currentColumn.length() > 0 ) {
      appendSpaces(currentColumn, potentialSpaces);
        }
        potentialSpaces = 0;

    } else {
        /*
         * Just a normal character. Add any required spaces (but trim any leading spaces if surrounding
         * spaces need quotes), add the character, then continue to next character.
         */
        if( this.strictQuotes && espectQuote ) {

      throw new SuperCsvException(
                String.format(
                  "strictQuotes: quotes needed at line %d column %d. To proceed, " +
                  "either quote the column or remove --strictquotes",
                  getLineNumber(), columns.size() + 1));
        }
        if( !surroundingSpacesNeedQuotes || currentColumn.length() > 0 ) {
      appendSpaces(currentColumn, potentialSpaces);
        }

        potentialSpaces = 0;
        currentColumn.append(c);
    }

      } else {

    /*
     * QUOTE_MODE (within quotes).
     */
        if( sawNewLineInQuote ) {
            if( currentColumn.length() > columnSizeLimit ) {
                state = TokenizerState.NORMAL;
                sawNewLineInQuote = false;
                throw new SuperCsvException(
                        String
                        .format(
                                "oversized column while reading quoted column %d beginning on line %d and ending on line %d. " +
                                "See --columnsizelimit.",
                                columns.size() + 1, quoteScopeStartingLine, getLineNumber()));
            }
        }
    if( c == NEWLINE ) {

        /*
         * Newline. Doesn't count as newline while in QUOTESCOPE. Add the newline char, reset the charIndex
         * (will update to 0 for next iteration), read in the next line, then then continue to next
         * character. For a large file with an unterminated quoted section (no trailing quote), this could
         * cause memory issues as it will keep reading lines looking for the trailing quote. Maybe there
         * should be a configurable limit on max lines to read in quoted mode?
         *
         * Yes I'll set the limit to be 16*1024*1024B = 16MB by default
         */
        if( currentColumn.length() > columnSizeLimit ) {
            state = TokenizerState.NORMAL;
            sawNewLineInQuote = false;
            throw new SuperCsvException(
                    String
                    .format(
                            "oversized column while reading quoted column %d beginning on line %d and ending on line %d. " +
                            "See --columnsizelimit.",
                            columns.size() + 1, quoteScopeStartingLine, getLineNumber()));
        }
        sawNewLineInQuote = true;
        currentColumn.append(NEWLINE);
        currentRow.append(NEWLINE); // specific line terminator lost, \n will have to suffice

        charIndex = -1;
        line = readLine();
        if( line == null ) {
      throw new SuperCsvException(
                String
                .format(
                  "unexpected end of file while reading quoted column %d beginning on line %d and ending on line %d",
                  columns.size() + 1, quoteScopeStartingLine, getLineNumber()));
        }
View Full Code Here

TOP

Related Classes of org.supercsv.exception.SuperCsvException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.