private VectorDataNodeReader(String sourceName, Product product, Reader reader, FeatureUtils.FeatureCrsProvider crsProvider, PlacemarkDescriptorProvider placemarkDescriptorProvider, boolean convertToVertices, char delimiterChar) throws IOException { this.product = product; this.crsProvider = crsProvider; this.placemarkDescriptorProvider = placemarkDescriptorProvider; this.convertToVertices = convertToVertices; this.sourceName = sourceName; this.reader = new CsvReader(reader, new char[]{delimiterChar}, true, "#"); }
private static void readGridConfig(int rowCount, int numRecords, int[] reducedColumnCount, double[] latitudePoints, int[] reducedFirstBinIndexes) throws IOException { InputStream is = GaussianGridConfig.class.getResourceAsStream(String.format("N%d.txt", rowCount)); reducedFirstBinIndexes[0] = 0; try (CsvReader csvReader = new CsvReader(new InputStreamReader(is), new char[]{'\t'}, true, "#")) { for (int i = 0; i < numRecords; i++) { String[] record = csvReader.readRecord(); reducedColumnCount[i] = Integer.parseInt(record[0]); latitudePoints[i] = Double.parseDouble(record[2]); if (i > 0) { reducedFirstBinIndexes[i] = reducedFirstBinIndexes[i - 1] + reducedColumnCount[i - 1]; } } } }
private static CsvReader openCsvReader(URL url) throws DDDBException { Debug.assertNotNull(url); try { return new CsvReader(new InputStreamReader(url.openStream()), FIELD_SEPARATORS); } catch (IOException e) { StringBuffer sb = new StringBuffer(); sb.append("failed to open DDDB resource: "); /*I18N*/ sb.append(e.getMessage()); sb.append(": file "); sb.append(url); throw new DDDBException(sb.toString()); } }
/** * Retrieves a csv reader opened at the first line of the file pased in * * @param filename * @return * @throws java.io.IOException */ private CsvReader getCsvReader(final String filename) throws IOException { final URL dbResource = getDatabaseResource(filename); final CsvReader reader; try { reader = new CsvReader(new InputStreamReader(dbResource.openStream()), ModisConstants.FIELD_SEPARATORS, true, "#"); } catch (MalformedURLException e) { throw new IOException(e.getMessage()); } return reader; }
private static CsvReader createReader(String csv,boolean ignoreEmptyLines, String commentPrefix, char... separators) { Reader reader = new StringReader(csv); return new CsvReader(reader, separators, ignoreEmptyLines, commentPrefix); }
protected static HashMap<String, String> readTwoColumnTable(String resourceName) { final InputStream stream = SeadasProductReader.class.getResourceAsStream(resourceName); if (stream != null) { try { HashMap<String, String> validExpressionMap = new HashMap<String, String>(32); final CsvReader csvReader = new CsvReader(new InputStreamReader(stream), new char[]{';'}); final List<String[]> table = csvReader.readStringRecords(); for (String[] strings : table) { if (strings.length == 2) { validExpressionMap.put(strings[0], strings[1]); } } return validExpressionMap; } catch (IOException e) { // ? } finally { try { stream.close(); } catch (IOException e) { // ok } } } return new HashMap<String, String>(0); }
private static CsvReader createReader(String csv, char... separators) { Reader reader = new StringReader(csv); return new CsvReader(reader, separators); }
EqualizationLUT(Reader[] bandCoefficientReaders) throws IOException { coefficientsMapList = new ArrayList<>(bandCoefficientReaders.length); for (Reader bandCoefficientReader : bandCoefficientReaders) { final HashMap<Integer, double[]> coefMap = new HashMap<>(); try (CsvReader csvReader = new CsvReader(bandCoefficientReader, new char[]{' '})) { double[] coefs = csvReader.readDoubleRecord(); while (coefs != null) { coefMap.put(csvReader.getLineNumber() - 1, coefs); coefs = csvReader.readDoubleRecord(); } } coefficientsMapList.add(coefMap); } }
@SuppressWarnings("unchecked") private static Map<String, ScanLineLayout> readScanLineLayoutMap() throws IOException { final InputStream inputStream = ChrisFile.class.getResourceAsStream("scanLineLayout.csv"); final InputStreamReader inputStreamReader = new InputStreamReader(inputStream); final CsvReader csvReader = new CsvReader(inputStreamReader, new char[]{','}, true, "#"); try { final List<String[]> recordList = csvReader.readStringRecords(); final Map<String, ScanLineLayout> scanLineLayoutMap = new HashMap<String, ScanLineLayout>( recordList.size()); for (final String[] record : recordList) { final int leadingPixelCount = Integer.parseInt(record[1]); final int imagePixelCount = Integer.parseInt(record[2]); final int trailingPixelCount = Integer.parseInt(record[3]); scanLineLayoutMap.put(record[0], new ScanLineLayout(leadingPixelCount, imagePixelCount, trailingPixelCount)); } return scanLineLayoutMap; } finally { try { csvReader.close(); } catch (IOException ignored) { // ignore } } } }
public static DiagramGraph[] readGraphs(Reader reader) throws IOException { CsvReader csvReader = new CsvReader(reader, new char[]{'\t'}); List<DiagramGraph> graphGroup = new ArrayList<DiagramGraph>(5); List<double[]> dataRecords = new ArrayList<double[]>(20); String[] headerRecord = csvReader.readRecord(); while (true) { if (headerRecord.length < 2) { throw new IOException("Invalid format."); } String[] record = csvReader.readRecord(); if (record == null) { break; } double[] dataRecord = toDoubles(record); if (dataRecord != null) { if (dataRecord.length != headerRecord.length) { throw new IOException("Invalid format."); } dataRecords.add(dataRecord); } else { readGraphGroup(headerRecord, dataRecords, graphGroup); headerRecord = record; } } readGraphGroup(headerRecord, dataRecords, graphGroup); return graphGroup.toArray(new DiagramGraph[0]); }
private static List<Endmember> readGraphs(Reader reader) throws IOException { CsvReader csvReader = new CsvReader(reader, new char[]{'\t'}); List<Endmember> endmemberList = new ArrayList<Endmember>(5); List<double[]> dataRecords = new ArrayList<double[]>(20); String[] headerRecord = csvReader.readRecord(); while (true) { if (headerRecord.length < 2) { throw new IOException("Invalid format."); } String[] record = csvReader.readRecord(); if (record == null) { break; } double[] dataRecord = toDoubles(record); if (dataRecord != null) { if (dataRecord.length != headerRecord.length) { throw new IOException("Invalid format."); } dataRecords.add(dataRecord); } else { readGraphGroup(headerRecord, dataRecords, endmemberList); headerRecord = record; } } readGraphGroup(headerRecord, dataRecords, endmemberList); return endmemberList; }
final CsvReader csvReader = new CsvReader(new InputStreamReader(in), fieldSeparators);
static FeatureCollection<SimpleFeatureType, SimpleFeature> readTrack(Reader reader, GeoCoding geoCoding) throws IOException { CsvReader csvReader = new CsvReader(reader, new char[]{'\t', ' '}, true, "#"); SimpleFeatureType trackFeatureType = createTrackFeatureType(geoCoding); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = new ListFeatureCollection(trackFeatureType);
private List<AttributeDescriptor> getAttributeDescriptors(String input) throws IOException { CsvReader csvReader = new CsvReader(new StringReader(input), new char[]{'\t'}, true, "#"); SimpleFeatureType simpleFeatureType = VectorDataNodeReader.read("blah", csvReader, createDummyProduct(), crsProvider, placemarkDescriptorProvider, DefaultGeographicCRS.WGS84, VectorDataNodeIO.DEFAULT_DELIMITER_CHAR, ProgressMonitor.NULL).getFeatureType(); assertNotNull(simpleFeatureType); assertEquals(9, simpleFeatureType.getAttributeCount()); return simpleFeatureType.getAttributeDescriptors(); }
private static void existsInFile(String[] expectedValues, String resourcePath) throws IOException { CsvReader csvReader = new CsvReader(createLineReader(resourcePath), new char[]{'|'}, true, "#"); List<String[]> recordSet = csvReader.readStringRecords(); try { for (String expectedValue : expectedValues) { assertTrue("expected '" + expectedValue + "' in " + resourcePath, existsInRecordSet(expectedValue, recordSet, 0)); } } finally { csvReader.close(); } }
CsvReader csvReader = new CsvReader(new StringReader(output), new char[]{'\t'}, true, "#");