@Override public InputStream read() { return this.source.read(); }
public BinaryChangeSetDeserializer(final Resource resourceToReadFrom) throws IOException { this.resource = new ObjectInputStream(resourceToReadFrom.read()); this.hasMore = true; }
public ZipIterator(final Resource source) { this.source = source; this.input = new ZipInputStream(new BufferedInputStream(this.source.read())); }
/** * @return A {@link BufferedReader} on this resource. */ default BufferedReader reader() { return new BufferedReader(new InputStreamReader(this.read(), StandardCharsets.UTF_8)); } }
public StreamOfResourceStreams(final Resource... resources) { super(Collections.enumeration(Stream.of(resources).map(resource -> resource.read()) .collect(Collectors.toList()))); } }
/** * Default constructor. * * @param resource * The OSM PBF {@link Resource} to use * @param loadingOption * The {@link AtlasLoadingOption} to use * @param boundingBox * The bounding box to consider when including features in the raw atlas */ public RawAtlasGenerator(final Resource resource, final AtlasLoadingOption loadingOption, final MultiPolygon boundingBox) { this(() -> new CloseableOsmosisReader(resource.read()), loadingOption, boundingBox); }
/** * Load a {@link MultiAtlas} from a serialized resource * * @param resource * The {@link Resource} to read from * @return The deserialized {@link MultiAtlas} */ public static MultiAtlas load(final Resource resource) { try (ObjectInputStream input = new ObjectInputStream(resource.read())) { final MultiAtlas result = (MultiAtlas) input.readObject(); return result; } catch (final Exception e) { throw new CoreException("Could not load Atlas from {}", e, resource); } }
/** * @return The contents of the resource as a byte[] */ default byte[] readBytesAndClose() { final List<Byte> byteContents = new ArrayList<>(); int kyte; try (InputStream input = new BufferedInputStream(read())) { while ((kyte = input.read()) >= 0) { byteContents.add((byte) (kyte & BYTE_MASK)); } } catch (final IOException e) { throw new CoreException("Unable to read the bytes from {}.", this, e); } final byte[] contents = new byte[byteContents.size()]; for (int index = 0; index < byteContents.size(); index++) { contents[index] = byteContents.get(index); } return contents; }
@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); } }
/** * Copy all the contents of this {@link Resource} to a {@link WritableResource} * * @param output * The output {@link WritableResource} */ default void copyTo(final WritableResource output) { try (InputStream inputStream = read(); OutputStream outputStream = output.write()) { IOUtils.copy(inputStream, outputStream); } catch (final Exception e) { throw new CoreException("Unable to copy {} to {}.", this, output, e); } }
public GeoJsonReader(final Resource source) { this.input = source.read(); this.reader = new JsonReader(new InputStreamReader(this.input)); final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Located.class, new LocatedDeserializer()); this.gson = builder.create(); try { this.reader.beginObject(); if (!"type".equals(this.reader.nextName()) || !"FeatureCollection".equals(this.reader.nextString())) { throw new CoreException("Malformed feature collection"); } String features = this.reader.nextName(); while (!"features".equals(features)) { // Read and skip the object (crs for example) this.gson.fromJson(this.reader, JsonObject.class); features = this.reader.nextName(); } this.reader.beginArray(); } catch (final Exception e) { Streams.close(this.input); throw new CoreException("Error reading GeoJson stream", e); } }
/** * Copy all of the contents of {@link Resource} to a {@link WritableResource} while notifying a * progress listener * * @param output * The output {@link WritableResource} * @param listener * The notification {@link IOProgressListener} called as data is being copied */ default void copyTo(final WritableResource output, final NotifyingIOUtils.IOProgressListener listener) { try (InputStream inputStream = read(); OutputStream outputStream = output.write()) { NotifyingIOUtils.copy(inputStream, outputStream, listener); } catch (final Exception e) { throw new CoreException("Unable to copy {} to {}.", this, output, e); } }
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); } }
try (InputStream input = resource.read())
inputStream = this.resource.read();
for (final Resource file : files) final JsonObject found = GSON_BUILDER.fromJson(new InputStreamReader(file.read()), JsonObject.class); if (Objects.nonNull(found))