@Override public void parseRecords(int offset, int numRecords) throws IOException { featureCollection = new ListFeatureCollection(simpleFeatureType); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(simpleFeatureType); skipToLine(offset); String line; long featureCount = offset; while ((numRecords == -1 || featureCount < offset + numRecords) && (line = stream.readLine()) != null) { String[] tokens = getTokens(line); if (tokens == null) { break; } int expectedTokenCount = simpleFeatureType.getAttributeCount(); expectedTokenCount += hasFeatureId ? 1 : 0; if (tokens.length != expectedTokenCount) { continue; } builder.reset(); String featureId = "" + featureCount++; for (int i = 0; i < tokens.length; i++) { String token = tokens[i]; if (i == 0 && hasFeatureId) { featureId = token; } else { try { Object value = null; int currentIndex = i; currentIndex -= hasFeatureId ? 1 : 0; if (!VectorDataNodeIO.NULL_TEXT.equals(token)) { value = converters[currentIndex].parse(token); } builder.set(simpleFeatureType.getDescriptor(currentIndex).getLocalName(), value); } catch (ConversionException e) { BeamLogManager.getSystemLogger() .warning(String.format("Problem in '%s': %s", csv.getPath(), e.getMessage())); } } } SimpleFeature simpleFeature = builder.buildFeature(featureId); featureCollection.add(simpleFeature); bytePositionForOffset.put(featureCount, stream.getStreamPosition()); } recordsParsed = true; }
@Override public Object[] parseRecords(final int offset, final int numRecords, final String rowName) throws IOException { AttributeDescriptor attributeDescriptor = simpleFeatureType.getDescriptor(rowName); int expectedTokenCount = simpleFeatureType.getAttributeCount(); expectedTokenCount += hasFeatureId ? 1 : 0; int rowIndex = simpleFeatureType.getAttributeDescriptors().indexOf(attributeDescriptor); int tokenIndex = rowIndex + (hasFeatureId ? 1 : 0); List<Object> values = new ArrayList<>(numRecords); skipToLine(offset); String line; long featureCount = offset; while ((numRecords == -1 || featureCount < offset + numRecords) && (line = stream.readLine()) != null) { String[] tokens = getTokens(line); if (tokens == null) { break; } if (tokens.length != expectedTokenCount) { continue; } featureCount++; String token = tokens[tokenIndex]; try { Object value = null; if (!VectorDataNodeIO.NULL_TEXT.equals(token)) { value = converters[rowIndex].parse(token); } values.add(value); } catch (ConversionException e) { BeamLogManager.getSystemLogger() .warning(String.format("Problem in '%s': %s", csv.getPath(), e.getMessage())); } bytePositionForOffset.put(featureCount, stream.getStreamPosition()); } return values.toArray(); }