org.openstreetmap.osmosis.dataset.v0_6.DumpDataset Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of osmosis-dataset Show documentation
Show all versions of osmosis-dataset Show documentation
Osmosis is a Java application and library for processing OSM data.
// This software is released into the Public Domain. See copying.txt for details.
package org.openstreetmap.osmosis.dataset.v0_6;
import java.util.Collections;
import org.openstreetmap.osmosis.core.OsmosisRuntimeException;
import org.openstreetmap.osmosis.core.container.v0_6.Dataset;
import org.openstreetmap.osmosis.core.container.v0_6.DatasetContext;
import org.openstreetmap.osmosis.core.container.v0_6.EntityContainer;
import org.openstreetmap.osmosis.core.lifecycle.ReleasableIterator;
import org.openstreetmap.osmosis.core.task.v0_6.DatasetSinkSource;
import org.openstreetmap.osmosis.core.task.v0_6.Sink;
/**
* Reads all data from a dataset.
*
* @author Brett Henderson
*/
public class DumpDataset implements DatasetSinkSource {
private Sink sink;
private DatasetContext datasetReader;
/**
* {@inheritDoc}
*/
@Override
public void setSink(Sink sink) {
this.sink = sink;
}
/**
* {@inheritDoc}
*/
@Override
public void process(Dataset dataset) {
ReleasableIterator bboxData;
if (datasetReader != null) {
throw new OsmosisRuntimeException("process may only be invoked once.");
}
datasetReader = dataset.createReader();
// Pass all data within the dataset to the sink.
bboxData = datasetReader.iterate();
try {
sink.initialize(Collections.emptyMap());
while (bboxData.hasNext()) {
sink.process(bboxData.next());
}
sink.complete();
} finally {
bboxData.release();
}
}
/**
* {@inheritDoc}
*/
@Override
public void release() {
sink.release();
if (datasetReader != null) {
datasetReader.release();
}
}
}