Search in sources :

Example 1 with RangesIterator

use of org.structr.api.util.RangesIterator in project structr by structr.

the class CsvHelper method cleanAndParseCSV.

public static Iterable<JsonInput> cleanAndParseCSV(final SecurityContext securityContext, final Reader input, final Class type, final Character fieldSeparator, final Character quoteCharacter, final String range, final Map<String, String> propertyMapping) throws FrameworkException, IOException {
    final CSVReader reader;
    if (quoteCharacter == null) {
        reader = new CSVReader(input, fieldSeparator);
    } else {
        reader = new CSVReader(input, fieldSeparator, quoteCharacter, true);
    }
    final String[] propertyNames = reader.readNext();
    return new Iterable<JsonInput>() {

        @Override
        public Iterator<JsonInput> iterator() {
            final Iterator<JsonInput> iterator = new CsvIterator(reader, propertyNames, propertyMapping, type, securityContext.getUser(false).getName());
            if (StringUtils.isNotBlank(range)) {
                return new RangesIterator<>(iterator, range);
            } else {
                return iterator;
            }
        }
    };
}
Also used : JsonInput(org.structr.core.JsonInput) RangesIterator(org.structr.api.util.RangesIterator) CSVReader(com.opencsv.CSVReader)

Aggregations

CSVReader (com.opencsv.CSVReader)1 RangesIterator (org.structr.api.util.RangesIterator)1 JsonInput (org.structr.core.JsonInput)1