org.openlr.binary.reader.CircleLocationReferenceReader Maven / Gradle / Ivy
The newest version!
package org.openlr.binary.reader;
import org.locationtech.jts.geom.Coordinate;
import org.openlr.binary.format.Status;
import org.openlr.locationreference.CircleLocationReference;
import org.openlr.locationreference.LocationReferenceFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
class CircleLocationReferenceReader {
private final LocationReferenceFactory locationReferenceFactory;
private final StatusReader statusReader;
private final CoordinateReader coordinateReader;
private final IntegerReader integerReader;
CircleLocationReferenceReader(LocationReferenceFactory locationReferenceFactory, StatusReader statusReader, CoordinateReader coordinateReader, IntegerReader integerReader) {
this.locationReferenceFactory = locationReferenceFactory;
this.statusReader = statusReader;
this.coordinateReader = coordinateReader;
this.integerReader = integerReader;
}
CircleLocationReference read(ByteArrayInputStream inputStream) throws IOException {
Status status = statusReader.read(inputStream);
if (status.getVersion() != 3) {
throw new IllegalArgumentException();
}
if (status.isAttributeFlag()) {
throw new IllegalArgumentException();
}
if (status.getAreaFlag() != 0) {
throw new IllegalArgumentException();
}
if (status.isPointFlag()) {
throw new IllegalArgumentException();
}
Coordinate center = coordinateReader.readAbsoluteCoordinate(inputStream);
int radius = integerReader.readUnsignedInteger(inputStream.available(), inputStream);
return locationReferenceFactory.createCircleLocationReference(center,radius);
}
}