initializeAddStage();
// We can only add nodes in sorted order.
if (nodeId <= lastNodeId) {
throw new OsmosisRuntimeException(
"The node id of " + nodeId
+ " must be greater than the previous id of "
+ lastNodeId + "."
);
}
lastNodeId = nodeId;
try {
// Write zeros to the file where no node data is available.
requiredFileOffset = nodeId * NODE_DATA_SIZE;
if (requiredFileOffset > currentFileOffset) {
while (currentFileOffset < requiredFileOffset) {
long offsetDifference;
offsetDifference = requiredFileOffset - currentFileOffset;
if (offsetDifference > ZERO_BUFFER_SIZE) {
offsetDifference = ZERO_BUFFER_SIZE;
}
dataOutStream.write(zeroBuffer, 0, (int) offsetDifference);
currentFileOffset += offsetDifference;
}
}
// Write the node data. Prefix with a non-zero byte to identify that
// data is available for this node.
dataOutStream.writeByte(1);
dataOutStream.writeInt(FixedPrecisionCoordinateConvertor.convertToFixed(nodeLocation.getLongitude()));
dataOutStream.writeInt(FixedPrecisionCoordinateConvertor.convertToFixed(nodeLocation.getLatitude()));
currentFileOffset += NODE_DATA_SIZE;
} catch (IOException e) {
throw new OsmosisRuntimeException(
"Unable to write node location data to node storage file "
+ nodeStorageFile + ".",
e
);
}