/** * @return A {@link StringList} of all the lines in this resource. */ default StringList linesList() { return new StringList(lines()); }
/** * Copy all the contents of another {@link Resource} to this {@link WritableResource} * * @param input * The input {@link Resource} */ default void copyFrom(final Resource input) { input.copyTo(this); }
@SuppressWarnings("unchecked") public StandardConfiguration(final Resource resource) { this.name = resource.getName(); try (InputStream read = resource.read()) { final ObjectMapper objectMapper = new ObjectMapper(); final SimpleModule simpleModule = new SimpleModule(); simpleModule.addDeserializer(Map.class, new ConfigurationDeserializer()); objectMapper.registerModule(simpleModule); final JsonParser parser = new JsonFactory().createParser(read); this.configurationData = objectMapper.readValue(parser, Map.class); } catch (final Exception oops) { throw new CoreException("Failure to load configuration", oops); } }
@Override public InputStream read() { return this.source.read(); }
@Test public void testZipResource() { final ZipResource resource = new ZipResource( new InputStreamResource(ZipResourceTest.class.getResourceAsStream("test.zip"))); int counter = 0; for (final Resource entry : resource.entries()) { final String name = entry.getName(); final String contents = entry.all(); logger.info(name + " -> " + contents); if (counter == 0) { Assert.assertEquals(NAME_1, name); Assert.assertEquals(CONTENTS_1, contents); } else { Assert.assertEquals(NAME_2, name); Assert.assertEquals(CONTENTS_2, contents); } counter++; } }
public String getName() { return this.source.getName(); }
long numberOfPoints = 0L; long numberOfRelations = 0L; for (final String line : resource.lines()) "unknown", "unknown", Maps.hashMap()); final PackedAtlasBuilder builder = new PackedAtlasBuilder().withSizeEstimates(size) .withMetaData(metaData).withName(resource.getName()); for (final String line : resource.lines())
protoAtlas = ProtoAtlas.parseFrom(resource.readBytesAndClose()); resource.getName(), exception); .withMetaData(atlasMetaData).withName(resource.getName());
if (this.useExactResourceSize) final long resourceLength = resource.get().length(); logger.trace("StrategyID {}: using extact resource length {}", this.getStrategyID(), resourceLength); resourceBytes = new ByteArrayResource(this.initialArraySize); resourceBytes.writeAndClose(resource.get().readBytesAndClose()); this.resourceCache.put(resourceUUID, resourceBytes);
@Test public void testReplacement() { final Resource josmOsmFile = new InputStreamResource( () -> OsmFileParserTest.class.getResourceAsStream("josmOsmFile.osm")); final Resource osmFile = new InputStreamResource( () -> OsmFileParserTest.class.getResourceAsStream("osmFile.osm")); final StringResource result = new StringResource(); new OsmFileParser().update(josmOsmFile, result); Assert.assertEquals(osmFile.all(), result.all()); } }
@Override public long length() { return this.source.length(); }
.deserialize(resource.readBytesAndClose());
/** * Construct a new {@link PackedAtlasSerializer}. * * @param atlas * The {@link Atlas} to be serialized / deserialized * @param resource * The resource where to serialize / deserialize from. */ protected PackedAtlasSerializer(final PackedAtlas atlas, final Resource resource) { this.atlas = atlas; if (resource instanceof File && !resource.isGzipped()) { // Make sure to use ZipFileWritableResource to take advantage of the random access. this.source = new ZipFileWritableResource((File) resource); } else if (resource instanceof WritableResource) { this.source = new ZipWritableResource((WritableResource) resource); } else { this.source = new ZipResource(resource); } }
for (final Resource file : files) final String ldgeojson = file.readAndClose();
public BinaryChangeSetDeserializer(final Resource resourceToReadFrom) throws IOException { this.resource = new ObjectInputStream(resourceToReadFrom.read()); this.hasMore = true; }
@Test public void testZipFile() { final File source = File.temporary(); logger.info("testZipFile using {}", source); try { final ZipFileWritableResource zipFile = new ZipFileWritableResource(source); zipFile.writeAndClose(new StringResource(CONTENTS_1).withName(NAME_1), new StringResource(CONTENTS_2).withName(NAME_2)); // Try to access entries randomly final Resource entry2 = zipFile.entryForName(NAME_2); final String name2 = entry2.getName(); final String contents2 = entry2.all(); logger.info(name2 + " -> " + contents2); Assert.assertEquals(NAME_2, name2); Assert.assertEquals(CONTENTS_2, contents2); final Resource entry1 = zipFile.entryForName(NAME_1); final String name1 = entry1.getName(); final String contents1 = entry1.all(); logger.info(name1 + " -> " + contents1); Assert.assertEquals(NAME_1, name1); Assert.assertEquals(CONTENTS_1, contents1); } finally { source.delete(); logger.info("testZipFile deleted {}", source); } }
@Test public void testSaveWhenBuildingFromFile() { final CountryToShardListCache cache = new CountryToShardListCache(this.countryToShardList); // test that you get the same file back that was used to initialize the cache final ByteArrayResource output = new ByteArrayResource(); cache.save(output); Assert.assertEquals(this.countryToShardList.all(), output.all()); }
protected static Node read(final Resource resource) { return read(resource.lines().iterator()); }
private Object deserializeJavaResource(final Resource resource) { try (ObjectInputStream input = new ObjectInputStream(decompress(resource.read()))) { final Time start = Time.now(); final Object result = input.readObject(); Streams.close(input); logger.trace("Loaded Field {} from {} in {}", resource.getName(), this.source, start.elapsedSince()); return result; } catch (final Exception e) { throw new CoreException("Could not load Field {} from {}", resource.getName(), this.source, e); } }