if (entry != null) return new InputStreamResource(inputStreamSupplier(file, entry)).withName(name);
@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 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()); }
@Test public void testNullSubAtlasAfterFiltering() { // Filter that brings in only Edges with highway tag tertiary or greater final Predicate<AtlasEntity> edgesTertiaryOrGreater = entity -> entity instanceof Edge && Validators.from(HighwayTag.class, (Edge) entity).isPresent() && Validators.from(HighwayTag.class, (Edge) entity).get() .isMoreImportantThan(HighwayTag.TERTIARY); // Load atlas with only edges tertiary or greater and check that it is null as expected final Atlas atlasWithEdgesTertiaryOrGreater = new AtlasResourceLoader() .withAtlasEntityFilter(edgesTertiaryOrGreater) .load(new InputStreamResource(() -> AtlasResourceLoaderTest.class .getResourceAsStream("ECU_6-16-31.atlas")).withName("ECU_6-16-31.atlas")); Assert.assertEquals(null, atlasWithEdgesTertiaryOrGreater); } }
@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")))); }
.getResourceAsStream("NZL_9-506-316.atlas.gz")) .withDecompressor(Decompressor.GZIP) .withName("NZL_9-506-316.atlas.gz")); .withDecompressor(Decompressor.GZIP).withName("NZL_9-506-316.atlas.gz")); .getResourceAsStream("NZL_9-506-316.atlas.gz")) .withDecompressor(Decompressor.GZIP) .withName("NZL_9-506-316.atlas.gz"));