Package org.apache.commons.csv

Examples of org.apache.commons.csv.CSVParser


        Reader reader = null;
        boolean error = false;
        try {
            reader = IOHelper.buffered(new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange)));
            CSVParser parser = new CSVParser(reader, strategy);
            if (skipFirstLine) {
                // read one line ahead and skip it
                parser.getLine();
            }
            CsvLineConverter<?> lineConverter;
            if (useMaps) {
                final CSVField[] fields = this.config.getFields();
                final String[] fieldS;
                if (fields != null && fields.length > 0) {
                    fieldS = new String[fields.length];
                    for (int i = 0; i < fields.length; i++) {
                        fieldS[i] = fields[i].getName();
                    }
                } else {
                    fieldS = parser.getLine();
                }
                lineConverter = CsvLineConverters.getMapLineConverter(fieldS);
            } else {
                lineConverter = CsvLineConverters.getListConverter();
            }
View Full Code Here


        if (delimiter != null) {
            strategy.setDelimiter(delimiter.charAt(0));
        }
       
        try {
            CSVParser parser = new CSVParser(in, strategy);
            List<List<String>> list = new ArrayList<List<String>>();
            while (true) {
                String[] strings = parser.getLine();
                if (strings == null) {
                    break;
                }
                List<String> line = Arrays.asList(strings);
                list.add(line);
View Full Code Here

        public CSVRecord parse(String input) throws IOException {
            // TODO Creating a new parser for each line seems terribly inefficient but
            // there's no public way to parse single lines via commons-csv. We should update
            // it to create a LineParser class like this one.
            CSVParser csvParser = new CSVParser(new StringReader(input), csvFormat);
            return Iterables.getFirst(csvParser, null);
        }
View Full Code Here

        strategy.setDelimiter(config.getDelimiter());

        InputStreamReader in = new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange));

        try {
            CSVParser parser = new CSVParser(in, strategy);
            List<List<String>> list = new ArrayList<List<String>>();
            boolean isFirstLine = true;
            while (true) {
                String[] strings = parser.getLine();
                if (isFirstLine) {
                    isFirstLine = false;
                    if (skipFirstLine) {
                        // skip considering the first line if we're asked to do so
                        continue;
View Full Code Here

    }

    public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
        InputStreamReader in = new InputStreamReader(inputStream);
        try {
            CSVParser parser = new CSVParser(in, getStrategy());
            List<List<String>> list = new ArrayList<List<String>>();
            while (true) {
                String[] strings = parser.getLine();
                if (strings == null) {
                    break;
                }
                List<String> line = Arrays.asList(strings);
                list.add(line);
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(OperatingSystemExamplesReader.class);

  public static List<OperatingSystemExample> read() {
    final InputStream stream = UserAgentStringParserIntegrationTest.class.getClassLoader().getResourceAsStream(FILE);

    CSVParser csvParser = null;
    try {
      csvParser = new CSVParser(new InputStreamReader(stream, CHARSET));
    } catch (final UnsupportedEncodingException e) {
      LOG.warn(e.getLocalizedMessage(), e);
    }

    final List<OperatingSystemExample> examples = new ArrayList<OperatingSystemExample>(200);
    if (csvParser != null) {
      String[] line = null;
      int i = 0;
      do {

        try {
          line = csvParser.getLine();
        } catch (final IOException e) {
          line = null;
          LOG.warn(e.getLocalizedMessage(), e);
        }
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(UserAgentExamplesReader.class);

  public static List<UserAgentExample> read() {
    final InputStream stream = UserAgentStringParserIntegrationTest.class.getClassLoader().getResourceAsStream(FILE);

    CSVParser csvParser = null;
    try {
      csvParser = new CSVParser(new InputStreamReader(stream, CHARSET));
    } catch (final UnsupportedEncodingException e) {
      LOG.warn(e.getLocalizedMessage(), e);
    }

    final List<UserAgentExample> examples = new ArrayList<UserAgentExample>(2000);
    if (csvParser != null) {
      String[] line = null;
      int i = 0;
      do {

        try {
          line = csvParser.getLine();
        } catch (final IOException e) {
          LOG.warn(e.getLocalizedMessage(), e);
          line = null;
        }
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(OperatingSystemSampleReader.class);

  private static List<OperatingSystemSample> read(final String file) {
    final InputStream stream = UserAgentStringParserIntegrationTest.class.getClassLoader().getResourceAsStream(file);

    CSVParser csvParser = null;
    try {
      csvParser = new CSVParser(new InputStreamReader(stream, CHARSET));
    } catch (final UnsupportedEncodingException e) {
      LOG.warn(e.getLocalizedMessage(), e);
    }

    final List<OperatingSystemSample> examples = new ArrayList<OperatingSystemSample>();
    if (csvParser != null) {
      String[] line = null;
      int i = 0;
      do {

        try {
          line = csvParser.getLine();
        } catch (final IOException e) {
          line = null;
          LOG.warn(e.getLocalizedMessage(), e);
        }
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(DeviceCategoryExamplesReader.class);

  public static List<DeviceCategoryExample> read() {
    final InputStream stream = UserAgentStringParserIntegrationTest.class.getClassLoader().getResourceAsStream(FILE);

    CSVParser csvParser = null;
    try {
      csvParser = new CSVParser(new InputStreamReader(stream, CHARSET));
    } catch (final UnsupportedEncodingException e) {
      LOG.warn(e.getLocalizedMessage(), e);
    }

    final List<DeviceCategoryExample> examples = new ArrayList<DeviceCategoryExample>(2000);
    if (csvParser != null) {
      String[] line = null;
      int i = 0;
      do {

        try {
          line = csvParser.getLine();
        } catch (final IOException e) {
          LOG.warn(e.getLocalizedMessage(), e);
          line = null;
        }
View Full Code Here

public class CSVVectorIterator extends AbstractIterator<Vector> {

  private final CSVParser parser;

  public CSVVectorIterator(Reader reader) {
    parser = new CSVParser(reader);
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.csv.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.