protected Iterable<PropertiesLocated> readGeoJsonItems(final Mode mode, final Iterable<File> files, final String filePrefix) { switch (mode) { case FILE: return Iterables.stream(files) .filter(file -> file.getName().endsWith(FileSuffix.GEO_JSON.toString())) .flatMap(this::readGeoJsonItems); case LINE: return Iterables.stream(files).filter(file -> file.getName().startsWith(filePrefix)) .flatMap(file -> file.lines()).map(line -> line.trim()) .filter(line -> !line.isEmpty()).flatMap(this::readGeoJsonItems); default: throw new CoreException("Invalid Mode"); } }
@Test public void testThreadSafety() throws IOException { final File outputPath = File.temporary(); try { AtlasReader.main("featureCounts", String.format("-input=%s", AtlasFeatureCountsSubCommandTestCase.temporaryFolder), "-parallel", String.format("-output=%s", outputPath)); final boolean[] found = { false }; Iterables.filter(outputPath.lines(), line -> line.contains("JPN-NODE")).forEach(line -> { final String[] fields = line.split(":"); Assert.assertEquals(4, Integer.parseInt(fields[1].trim())); found[0] = true; }); Assert.assertTrue(found[0]); } finally { outputPath.delete(); } } }
@Override protected int onRun(final CommandMap command) { final String delimiter = (String) command.get(DELIMITER); final File inputFile = (File) command.get(POLYLINES); final Iterable<List<PolyLine>> inputs = Iterables.stream(inputFile.lines()) .map(line -> StringList.split(line, delimiter).stream() .map(WKT_POLY_LINE_CONVERTER::backwardConvert) .collect(Collectors.toList())); try (SafeBufferedWriter writer = writer(command)) { for (final List<PolyLine> input : inputs) { writer.writeLine(new StringList( Iterables.stream(MULTIPLE_POLY_LINE_TO_POLYGONS_CONVERTER.convert(input)) .map(Polygon::toWkt)).join(delimiter)); } } catch (final Exception e) { throw new CoreException("Unable to convert polylines from {}", inputFile.getName(), e); } return 0; }