public StringResource(final InputStream source) { this(new InputStreamResource(source)); }
/** * Parse the output logs of a {@link Process}. * * @param standardOut * The output stream for standard output * @param standardErr * The output stream for standard error */ protected void parse(final InputStream standardOut, final InputStream standardErr) { this.out = new Thread( () -> parseStandardOutput(new InputStreamResource(standardOut).lines())); this.err = new Thread( () -> parseStandardError(new InputStreamResource(standardErr).lines())); this.out.setPriority(Thread.MAX_PRIORITY); this.err.setPriority(Thread.MAX_PRIORITY); this.out.start(); this.err.start(); }
if (entry != null) return new InputStreamResource(inputStreamSupplier(file, entry)).withName(name);
@Test public void testSingleClosedPolyLineWithinGroup() { final List<PolyLine> input = new InputStreamResource( () -> MultiplePolyLineToPolygonsConverterTest.class .getResourceAsStream("multiplePolyLines.txt")).linesList().stream() .map(WKT_POLY_LINE_CONVERTER::backwardConvert) .collect(Collectors.toList()); final List<Polygon> expected = new InputStreamResource( () -> MultiplePolyLineToPolygonsConverterTest.class .getResourceAsStream("expectedPolygons.txt")).linesList().stream() .map(WKT_POLYGON_CONVERTER::backwardConvert) .collect(Collectors.toList()); Assert.assertEquals(expected, Iterables.asList(CONVERTER.convert(input))); }
@Test(expected = CoreException.class) public void testGridIndexReconstructionWithMissingCountryCode() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final Set<String> countries = new HashSet<>( Arrays.asList("HTI", "DOM", /* Not there on purpose */"CIV")); // This is expected to throw a CoreException listing the missing country, versus a NPE. map.initializeGridIndex(countries); }
@Test public void testBigNodeWithNoRestrictions() { final Atlas atlas = new TextAtlasBuilder().read(new InputStreamResource( () -> ComplexTurnRestrictionTest.class.getResourceAsStream("bigNode.txt.gz")) .withDecompressor(Decompressor.GZIP).withName("bigNode.txt.gz")); final List<BigNode> bigNodes = Iterables.asList(new BigNodeFinder().find(atlas)); final Optional<BigNode> possibleBigNode = bigNodes.stream() .filter(bigNode -> bigNode.getOsmIdentifier() == 3717537957L).findAny(); Assert.assertTrue(possibleBigNode.isPresent()); final BigNode bigNode = possibleBigNode.get(); Assert.assertTrue(!bigNode.allPaths().isEmpty()); Assert.assertTrue(bigNode.turnRestrictions().isEmpty()); }
private void assertEquals(final Change change, final String fileName) { final String expected = new InputStreamResource( () -> ChangeGeoJsonSerializerTest.class.getResourceAsStream(fileName)).all(); Assert.assertEquals(expected, change.toJson()); final File temporary = File.temporary(); try { change.save(temporary); Assert.assertEquals(expected, temporary.all()); } finally { temporary.delete(); } } }
@Test public void testNearestNeighborCountryCodeOnMultiLineStringOutsideBoundary() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("DMA_boundary.txt"))); map.setShouldAlwaysSlicePredicate(taggable -> true); final PolyLine polyLine = PolyLine.wkt(new InputStreamResource( () -> CountryBoundaryMapTest.class.getResourceAsStream("DMA_snake_polyline.wkt")) .firstLine()); final List<Geometry> sliced = map.slice(123000000L, new JtsPolyLineConverter().convert(polyLine), Taggable.with("force-slice", "please")); int withNearestNeighborTag = 0; for (final Geometry slicedGeometry : sliced) { if (SyntheticNearestNeighborCountryCodeTag.YES.name() .equals(CountryBoundaryMap.getGeometryProperty(slicedGeometry, SyntheticNearestNeighborCountryCodeTag.KEY))) { withNearestNeighborTag++; } } Assert.assertEquals(3, withNearestNeighborTag); }
public InputStreamResource withName(final String name) { this.setName(name); return this; }
public InputStreamResource withDecompressor(final Decompressor decompressor) { this.setDecompressor(decompressor); return this; }
private static void testAndValidateGridIndexConsistency(final Set<String> countries, final String filename) { // Generate grid index for the first time final CountryBoundaryMap firstMap = CountryBoundaryMap.fromPlainText( new InputStreamResource(CountryBoundaryMapTest.class.getResourceAsStream(filename)) .withDecompressor(Decompressor.GZIP)); firstMap.initializeGridIndex(countries); // Generate grid index for the second time final CountryBoundaryMap secondMap = CountryBoundaryMap.fromPlainText( new InputStreamResource(CountryBoundaryMapTest.class.getResourceAsStream(filename)) .withDecompressor(Decompressor.GZIP)); secondMap.initializeGridIndex(countries); // Compare Assert.assertTrue(CountryBoundaryMapCompareCommand.areSTRtreesEqual(firstMap.getGridIndex(), secondMap.getGridIndex())); }
.load(new InputStreamResource(() -> AtlasResourceLoaderTest.class .getResourceAsStream("NZL_9-506-316.atlas.gz")) .withDecompressor(Decompressor.GZIP) .withName("NZL_9-506-316.atlas.gz")); final Atlas atlasWithoutFilter = new AtlasResourceLoader().load(new InputStreamResource( () -> AtlasResourceLoaderTest.class.getResourceAsStream("NZL_9-506-316.atlas.gz")) .withDecompressor(Decompressor.GZIP).withName("NZL_9-506-316.atlas.gz")); .load(new InputStreamResource(() -> AtlasResourceLoaderTest.class .getResourceAsStream("NZL_9-506-316.atlas.gz")) .withDecompressor(Decompressor.GZIP) .withName("NZL_9-506-316.atlas.gz"));
private void assertEquals(final FeatureChange featureChange, final String fileName) { final String expected = new InputStreamResource( () -> FeatureChangeGeoJsonSerializerTest.class.getResourceAsStream(fileName)).all(); Assert.assertEquals(expected, featureChange.toJson()); final File temporary = File.temporary(); try { featureChange.save(temporary); Assert.assertEquals(expected, temporary.all()); } finally { temporary.delete(); } } }
/** * Resolves a {@link Configuration} from the classpath * * @param path * a fully qualified resource name * @param context * a {@code Class} to get the {@code ClassLoader} from * @return a new {@link Configuration} */ public static Configuration resourceConfiguration(final String path, final Class context) { try (InputStream config = context.getResourceAsStream(path)) { return new StandardConfiguration(new InputStreamResource(config)); } catch (final IOException oops) { Assert.fail(oops.getMessage()); } return null; }
@Test public void testFeatureCrossingCountryBoundary() throws ParseException { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final WKTReader reader = new WKTReader(); final Geometry geometry = reader.read( "POLYGON (( -71.7424191 18.7499411097, -71.730485136 18.749848501, -71.730081575 18.749979671, -71.730142154 18.749575218, -71.730486015 18.7498444, -71.7424191 18.7499411097 ))"); final List<Geometry> pieces = map.slice(1000000L, geometry); logger.info(pieces.toString()); Assert.assertEquals(2, pieces.size()); }
@Override public Iterable<Resource> entries() { try (ZipFile file = new ZipFile(getFileSource().getFile()) { @Override public void close() { // Do nothing to close the file here, to avoid cutting the legs off the just created // ZipEntry-based resource. } }) { return Iterables.translate(Iterables.from(file.entries()), entry -> { return new InputStreamResource(inputStreamSupplier(file, entry)) .withName(entry.getName()); }); } catch (final IOException e) { throw new CoreException("Cannot get entries from the Zipfile {}.", this.getFileSource().getName(), e); } }
@Test public void splitTest() { final InputStream input = new StringInputStream("line1: blah\nline2: haha"); final SplittableInputStream split = new SplittableInputStream(input); final InputStream in2 = split.split(); logger.info("{}", Iterables.asList(new InputStreamResource(split).lines())); logger.info("{}", Iterables.asList(new InputStreamResource(in2).lines())); Streams.close(split); } }
@Before public void init() { this.resource = new InputStreamResource( CsvReaderTest.class.getResourceAsStream("data.csv")); this.wrongResource = new InputStreamResource( CsvReaderTest.class.getResourceAsStream("wrongData.csv")); // Create the schema with 3 converters in order. this.schema = new CsvSchema(CONVERTER1, CONVERTER2, CONVERTER3); }
@Test public void testAntiMeridian() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final LineString lineString = (LineString) TestUtility .createJtsGeometryFromWKT("LINESTRING ( -179 18.84927, 179 18.84927 )"); // HTI is the closest to the line Assert.assertEquals("HTI", map.getCountryCodeISO3(lineString).getIso3CountryCode()); }
@Test public void testInputStreamResource() { // input stream resources require name to be set explicitly Assert.assertTrue(PREDICATE.test(new InputStreamResource(new StringInputStream("foo bar")) .withName("/some/path/XYZ_11-1095-641.atlas.gz"))); Assert.assertFalse( PREDICATE.test(new InputStreamResource(new StringInputStream("foo bar")))); }