use of org.openstreetmap.osmosis.pbf2.v0_6.impl.HeaderBoundReader in project osmosis by openstreetmap.
the class PbfReader method run.
@Override
public void run() {
StreamSplitter streamSplitter = null;
ExecutorService executorService;
if (workers > 0) {
executorService = Executors.newFixedThreadPool(workers);
} else {
executorService = MoreExecutors.newDirectExecutorService();
}
try {
InputStream inputStream = supplier.get();
// Create a stream splitter to break the PBF stream into blobs.
streamSplitter = new StreamSplitter(new DataInputStream(inputStream));
// Obtain the header block.
Osmformat.HeaderBlock header = new HeaderSeeker().apply(streamSplitter);
// Get the pipeline metadata (e.g. do ways include location information) from header.
Map<String, Object> metadata = new HeaderMetadataReader().apply(header);
sink.initialize(metadata);
// Get Bound information from the header.
BoundContainer bound = new HeaderBoundReader().apply(header);
sink.process(bound);
// Process all blobs of data in the stream using threads from the
// executor service. We allow the decoder to issue an extra blob
// than there are workers to ensure there is another blob
// immediately ready for processing when a worker thread completes.
// The main thread is responsible for splitting blobs from the
// request stream, and sending decoded entities to the sink.
PbfDecoder pbfDecoder = new PbfDecoder(streamSplitter, executorService, workers + 1, sink);
pbfDecoder.run();
sink.complete();
} finally {
sink.close();
executorService.shutdownNow();
if (streamSplitter != null) {
streamSplitter.close();
}
}
}
Aggregations