Examples of CSVParser

There is one exception to the commonly-accepted parsing rules: Embedded line breaks in a quoted field are not parsed but instead interpreted as the premature end of a record. This was a deliberate decision given the scope of this parser and the fact that it parses only a single line of input. @author Johannes Rössel
  • weave.utils.CSVParser
    Parses and generates CSV-encoded tables. Also supports custom delimiters and quotes. @author adufilie

  • 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

    Examples of au.com.bytecode.opencsv.CSVParser

        @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

    Examples of au.com.bytecode.opencsv.CSVParser

            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

    Examples of au.com.bytecode.opencsv.CSVParser

            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

    Examples of au.com.bytecode.opencsv.CSVParser

            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

    Examples of au.com.bytecode.opencsv.CSVParser

         * 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

    Examples of au.com.bytecode.opencsv_voltpatches.CSVParser

            private final CSVParser m_csvParser;

            public KafkaConsumer(KafkaStream a_stream, CSVDataLoader loader) {
                m_stream = a_stream;
                m_loader = loader;
                m_csvParser = new CSVParser();
            }
    View Full Code Here

    Examples of com.Ostermiller.util.CSVParser

        private XMLEventReader r;

        Digester(Reader reader, String extension) throws HttpException {
          if (extension.equals("csv")) {
            shredder = new CSVParser(reader);
            shredder.setCommentStart("#");
            shredder.setEscapes("nrtf", "\n\r\t\f");

          } else if (extension.equals("xml")) {
            XMLInputFactory factory = XMLInputFactory.newInstance();
    View Full Code Here

    Examples of com.asakusafw.runtime.io.csv.CsvParser

                    CsvConfiguration.DEFAULT_TRUE_FORMAT,
                    CsvConfiguration.DEFAULT_FALSE_FORMAT,
                    CsvConfiguration.DEFAULT_DATE_FORMAT,
                    CsvConfiguration.DEFAULT_DATE_TIME_FORMAT);
            ByteArrayInputStream input = new ByteArrayInputStream(string.getBytes(conf.getCharset()));
            CsvParser parser = new CsvParser(input, string, conf);
            List<String[]> results = Lists.create();
            try {
                StringOption buffer = new StringOption();
                while (parser.next()) {
                    String[] line = new String[columns];
                    for (int i = 0; i < columns; i++) {
                        parser.fill(buffer);
                        line[i] = buffer.or((String) null);
                    }
                    parser.endRecord();
                    results.add(line);
                }
                parser.close();
            } catch (Exception e) {
                throw new AssertionError(e);
            }
            return results.toArray(new String[results.size()][]);
        }
    View Full Code Here

    Examples of com.asakusafw.runtime.io.csv.CsvParser

                    CsvConfiguration.DEFAULT_TRUE_FORMAT,
                    CsvConfiguration.DEFAULT_FALSE_FORMAT,
                    CsvConfiguration.DEFAULT_DATE_FORMAT,
                    CsvConfiguration.DEFAULT_DATE_TIME_FORMAT);
            ByteArrayInputStream input = new ByteArrayInputStream(string.getBytes(conf.getCharset()));
            CsvParser parser = new CsvParser(input, string, conf);
            List<String[]> results = Lists.create();
            try {
                StringOption buffer = new StringOption();
                while (parser.next()) {
                    String[] line = new String[columns];
                    for (int i = 0; i < columns; i++) {
                        parser.fill(buffer);
                        line[i] = buffer.or((String) null);
                    }
                    parser.endRecord();
                    results.add(line);
                }
                parser.close();
            } catch (Exception e) {
                throw new AssertionError(e);
            }
            return results.toArray(new String[results.size()][]);
        }
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. 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.