}
@Override
public void run() {
PbfStreamSplitter streamSplitter = null;
ExecutorService executorService = Executors.newFixedThreadPool(workers);
try {
InputStream inputStream;
sink.initialize(Collections.<String, Object>emptyMap());
// make "-" an alias for /dev/stdin
if (file.getName().equals("-")) {
inputStream = System.in;
} else {
inputStream = new FileInputStream(file);
}
// Create a stream splitter to break the PBF stream into blobs.
streamSplitter = new PbfStreamSplitter(new DataInputStream(inputStream));
// 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();
} catch (IOException e) {
throw new OsmosisRuntimeException("Unable to read PBF file " + file + ".", e);
} finally {
sink.release();
executorService.shutdownNow();
if (streamSplitter != null) {
streamSplitter.release();
}
}
}