CsvFile implements CsvSourceParser, CsvSource { private void parseProperties() throws IOException { String line; stream.seek(0); propertiesByteSize = 0; long posInStream = 0l; while ((line = stream.readLine()) != null) { if (!line.startsWith("#")) { stream.seek(posInStream); break; } propertiesByteSize += (stream.getStreamPosition() - posInStream); posInStream = stream.getStreamPosition(); line = line.substring(1); int pos = line.indexOf('='); if (pos == -1) { throw new IOException("Missing '=' in '" + line + "'"); } String name = line.substring(0, pos).trim(); if (name.isEmpty()) { throw new IOException("Empty property name in '" + line + "'"); } String value = line.substring(pos + 1).trim(); try { if (contains(Constants.CRS_IDENTIFIERS, name) && crs != null) { crs = CRS.parseWKT(value); } } catch (FactoryException e) { throw new IOException(e); } properties.put(name, value); } propertiesParsed = true; } private  CsvFile(String csv); private  CsvFile(File csv, CoordinateReferenceSystem crs); static CsvSourceParser createCsvSourceParser(String csv); @Override void checkReadingFirstRecord(); @Override Object[] parseRecords(final int offset, final int numRecords, final String rowName); @Override void parseRecords(int offset, int numRecords); @Override CsvSource parseMetadata(); @Override void close(); @Override int getRecordCount(); @Override SimpleFeature[] getSimpleFeatures(); @Override SimpleFeatureType getFeatureType(); @Override Map<String, String> getProperties(); static final String DEFAULT_HEADER_NAME; }
@Test public void testParseProperties() throws Exception { final String simpleFormatExample = getClass().getResource("reader/simple_format_example.txt").getFile(); final CsvSourceParser parser = CsvFile.createCsvSourceParser(simpleFormatExample); parser.parseMetadata(); final CsvSource source = parser.parseMetadata(); final Map<String,String> properties = source.getProperties(); assertNotNull(properties); assertEquals(5, properties.size()); assertEquals("POLYGON(0.0, 1.0, 1.1)", properties.get("geometry1")); assertEquals("POLYGON(2.0, 1.0, 1.1)", properties.get("geometry2")); assertEquals(",", properties.get("separator")); assertEquals("3", properties.get("sceneRasterWidth")); }