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 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);

                CsvLineConverter<?> lineConverter;
                if (useMaps) {
                    lineConverter = CsvLineConverters.getMapLineConverter(parser.getLine());
                } else {
                    lineConverter = CsvLineConverters.getListConverter();
                    if (skipFirstLine) {
                        // read one line ahead and skip it
                        parser.getLine();
                    }
                }

                @SuppressWarnings({"unchecked", "rawtypes"}) CsvIterator<?> csvIterator = new CsvIterator(parser, reader, lineConverter);
                return lazyLoad ? csvIterator : loadAllAsList(csvIterator);
    View Full Code Here

    Examples of org.apache.commons.csv.CSVParser

        }

        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

    Examples of org.apache.commons.csv.CSVParser

            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

    Examples of org.apache.commons.csv.CSVParser

         * @throws java.io.IOException
         */
        public static CSVParser build(InputStream is) throws IOException {
            CSVStrategy bestStrategy = getBestStrategy(is);
            if(bestStrategy == null) bestStrategy = getCSVStrategyFromConfiguration();
            return new CSVParser( new InputStreamReader(is), bestStrategy );
        }
    View Full Code Here

    Examples of org.apache.commons.csv.CSVParser

        private static boolean testStrategy(InputStream is, CSVStrategy strategy) throws IOException {
            final int MIN_COLUMNS = 2;

            is.mark(Integer.MAX_VALUE);
            try {
                final CSVParser parser = new CSVParser(new InputStreamReader(is), strategy);
                int linesToCheck = 5;
                int headerColumnCount = -1;
                while (linesToCheck > 0) {
                    String[] row;
                    row = parser.getLine();
                    if (row == null) {
                        break;
                    }
                    if (row.length < MIN_COLUMNS) {
                        return false;
    View Full Code Here

    Examples of org.apache.commons.csv.CSVParser

            for (int i=0; i<skipLines; i++) {
              r.readLine();
            }
          }

          CSVParser parser = new CSVParser(reader, strategy);

          // parse the fieldnames from the header of the file
          if (fieldnames==null) {
            fieldnames = parser.getLine();
            if (fieldnames==null) {
              throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Expected fieldnames in CSV input");
            }
            prepareFields();
          }

          // read the rest of the CSV file
          for(;;) {
            int line = parser.getLineNumber()// for error reporting in MT mode
            String[] vals = null;
            try {
              vals = parser.getLine();
            } catch (IOException e) {
              //Catch the exception and rethrow it with more line information
             input_err("can't read line: " + line, null, line, e);
            }
            if (vals==null) break;
    View Full Code Here

    Examples of org.apache.commons.csv.CSVParser

          this.base = base;
        }

        @Override
        void add(SolrInputDocument doc, int line, int column, String val) {
          CSVParser parser = new CSVParser(new StringReader(val), strategy);
          try {
            String[] vals = parser.getLine();
            if (vals!=null) {
              for (String v: vals) base.add(doc,line,column,v);
            } else {
              base.add(doc,line,column,val);
            }
    View Full Code Here

    Examples of org.apache.commons.csv.CSVParser

        }

        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

    Examples of org.apache.commons.csv.CSVParser

         *
         * @param fileName
         * @throws Exception
         */
        public void upsert(String fileName) throws Exception {
            CSVParser parser = CSVParser.parse(new File(fileName),
                    format);
            upsert(parser);
        }
    View Full Code Here

    Examples of org.apache.commons.csv.CSVParser

                    format);
            upsert(parser);
        }

        public void upsert(Reader reader) throws Exception {
            CSVParser parser = new CSVParser(reader,format);
            upsert(parser);
        }
    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.