Package au.com.bytecode.opencsv

Examples of au.com.bytecode.opencsv.CSVParser


            quoteChar = firstCharOrDefault(config.get("quote_char"), CSVParser.DEFAULT_QUOTE_CHARACTER);
            escapeChar = firstCharOrDefault(config.get("escape_char"), CSVParser.DEFAULT_ESCAPE_CHARACTER);
            strictQuotes = Objects.firstNonNull((Boolean) config.get("strict_quotes"), false);
            trimLeadingWhiteSpace = Objects.firstNonNull((Boolean) config.get("trim_leading_whitespace"), true);

            final CSVParser parser = getCsvParser();
            fieldNames = parser.parseLine(columnHeader);
            if (fieldNames.length == 0) {
                throw new ConfigurationException("No field names found.");
            }
        } catch (Exception e) {
            throw new ConfigurationException("Invalid configuration for CsvConverter");
View Full Code Here


    @Override
    public Object convert(String value) {
        if (value == null || value.isEmpty()) {
            return value;
        }
        final CSVParser parser = getCsvParser();
        final Map<String, String> fields = Maps.newHashMap();
        try {
            final String[] strings = parser.parseLine(value);
            if (strings.length != fieldNames.length) {
                LOG.error("Different number of columns in CSV data ({}) and configured field names ({}). Discarding input.",
                          strings.length, fieldNames.length);
                return null;
            }
View Full Code Here

        return defaultValue;
    }

    private CSVParser getCsvParser() {
        // unfortunately CSVParser has state, so we have to re-create it every time :(
        return new CSVParser(separator,
                             quoteChar,
                             escapeChar,
                             strictQuotes,
                             trimLeadingWhiteSpace);
    }
View Full Code Here

        if (_configuration.isMultilineValues()) {
            final CSVReader csvReader = createCsvReader(reader);
            return new CsvDataSet(csvReader, columns, maxRowsOrNull, columnCount, failOnInconsistentRowLength);
        }

        final CSVParser csvParser = new CSVParser(_configuration.getSeparatorChar(), _configuration.getQuoteChar(),
                _configuration.getEscapeChar());
        return new SingleLineCsvDataSet(reader, csvParser, columns, maxRowsOrNull, columnCount,
                failOnInconsistentRowLength);
    }
View Full Code Here

        return _values;
    }

    private String[] parseLine() {
        try {
            final CSVParser parser = _dataSet.getCsvParser();
            return parser.parseLine(_line);
        } catch (IOException e) {
            if (_failOnInconsistentRowLength) {
                throw new MetaModelException("Failed to parse CSV line no. " + _rowNumber + ": " + _line, e);
            } else {
                logger.warn("Encountered unparseable line no. {}, returning line as a single value with trailing nulls: {}", _rowNumber, _line);
View Full Code Here

     * Parses and imports the main player data section from the given CSV file content. Generates {@link Player} and {@link PlayerStats} entities.
     *
     * @throws ImportException if an error occurs
     */
    private void importPlayerData() throws ImportException {
        final CSVParser parser = new CSVParser(SEPARATOR);
        // use iterator because we are going to remove lines
        for (final Iterator<String[]> iterator = fileContent.iterator(); iterator.hasNext(); ) {
            final String[] line = iterator.next();
            // the array with player's playerRecord
            String[] playerRecord;
            try {
                // parse player's record and fill it into an array
                playerRecord = parser.parseLine(line[0]);
            } catch (final IOException ioe) {
                throw new ImportException(ResourceLoader.getMessage(MessageId.E002.getMessageKey()), ioe);
            }

            // if first part is numeric it is actually a player
View Full Code Here

     * Parses and imports the player history data section from the given CSV file content. Generates {@link PlayerHistory} entities.
     *
     * @throws ImportException if an error occurs
     */
    private void importPlayerHistory() throws ImportException {
        final CSVParser parser = new CSVParser(SEPARATOR);
        boolean historySectionFound = false;
        // use iterator because we are going to remove lines
        for (final Iterator<String[]> iterator = fileContent.iterator(); iterator.hasNext(); ) {
            final String[] line = iterator.next();
            // the array with player's history
            String[] playerHistory;
            try {
                // parse player's history and fill it into an array
                playerHistory = parser.parseLine(line[0]);
            } catch (final IOException ioe) {
                throw new ImportException(ResourceLoader.getMessage(MessageId.E002.getMessageKey()), ioe);
            }

            // if first part is numeric it is actually a player's history
View Full Code Here

  private void loadSystemMessages() {
    systemMessages = new HashMap<Integer, String>(2500,0.9f);
    try {
      CSVReader reader = new CSVReader(new InputStreamReader(
          CSVDatastoreDAO.class.getResourceAsStream("/db/systemmessages.csv")), 1/*skip header*/, new CSVParser('\t','"','\\'));
     
      String[] line = reader.readNext();
     
      while (line != null) {
        if (line.length > 1) {
View Full Code Here

  @Override
  public BaseUsable[] loadAllActions(){
    BaseUsable[] ret = new BaseUsable[0];
    try {
      CSVReader reader = new CSVReader(new InputStreamReader(
          CSVDatastoreDAO.class.getResourceAsStream("/db/actions.csv")), 1/*skip header*/, new CSVParser('\t','"','\\'));
      ret = ActionResultBuilder.buildActions(reader);
    } catch (Exception e) {
      logger.log(Level.SEVERE, "Failed to load /db/actions.csv", e);
    }
    return ret;
View Full Code Here

   */
  private void loadNPCs() {
    npcCache = new HashMap<Integer, CSVDatastoreDAO.CSVNpc>();
    try {
      CSVReader reader = new CSVReader(new InputStreamReader(
          CSVDatastoreDAO.class.getResourceAsStream("/db/npc.csv")), 1/*skip header*/, new CSVParser('\t','"','\\'));
     
      String[] line = reader.readNext();
      while (line != null) {
        if (line.length > 2) {
          CSVNpc n = new CSVNpc();
View Full Code Here

TOP

Related Classes of au.com.bytecode.opencsv.CSVParser

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.