use of com.revolsys.record.io.format.json.JsonParser in project com.revolsys.open by revolsys.
the class GeoJsonGeometryReader method readPolygon.
private Polygon readPolygon(final boolean cogo) {
List<LineString> rings = null;
GeometryFactory factory = this.geometryFactory;
do {
final JsonParser parser = this.in;
final String fieldName = parser.skipToNextAttribute();
if (GeoJson.COORDINATES.equals(fieldName)) {
rings = readCoordinatesListList(cogo, true);
} else if (GeoJson.CRS.equals(fieldName)) {
factory = readCoordinateSystem();
}
} while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
int axisCount = 2;
for (final LineString points : rings) {
axisCount = Math.max(axisCount, points.getAxisCount());
}
factory = factory.convertAxisCount(axisCount);
return factory.polygon(rings);
}
use of com.revolsys.record.io.format.json.JsonParser in project com.revolsys.open by revolsys.
the class ArcGisRestServerFeatureReader method getNext.
@SuppressWarnings("resource")
@Override
protected Record getNext() throws NoSuchElementException {
int previousRecordOffset = this.currentRecordId;
final int maxRetries = 3;
for (int retry = 0; retry < maxRetries; retry++) {
if (this.closed) {
throw new NoSuchElementException();
} else {
JsonParser parser = this.parser;
if (this.recordCount < this.queryLimit) {
if (parser == null) {
parser = newParser();
}
if (!parser.skipToNextObjectInArray()) {
if (this.pageByObjectId) {
parser = newParser();
if (!parser.skipToNextObjectInArray()) {
throw new NoSuchElementException();
}
} else if (this.supportsPaging) {
if (this.pageRecordCount == this.pageSize) {
parser = newParser();
if (!parser.skipToNextObjectInArray()) {
throw new NoSuchElementException();
}
}
} else {
throw new NoSuchElementException();
}
}
} else {
throw new NoSuchElementException();
}
if (this.closed) {
throw new NoSuchElementException();
} else {
try {
if (parser.isEvent(EventType.endArray, EventType.endDocument)) {
throw new NoSuchElementException();
}
final MapEx recordMap = this.parser.getMap();
final Record record = this.recordFacory.newRecord(this.recordDefinition);
record.setState(RecordState.INITIALIZING);
final MapEx fieldValues = recordMap.getValue("attributes");
final int recordId = fieldValues.getInteger(this.idFieldName, -1);
this.currentRecordId = recordId;
if (this.pageByObjectId) {
if (this.currentRecordId == -1) {
throw new NoSuchElementException();
}
}
record.setValues(fieldValues);
if (this.geometryConverter != null) {
final MapEx geometryProperties = recordMap.getValue("geometry");
if (Property.hasValue(geometryProperties)) {
final Geometry geometry = this.geometryConverter.apply(this.geometryFactory, geometryProperties);
record.setGeometryValue(geometry);
}
}
if (parser.hasNext()) {
final EventType nextEvent = parser.next();
if (nextEvent == EventType.endArray || nextEvent == EventType.endDocument) {
this.parser = null;
}
} else {
this.parser = null;
}
record.setState(RecordState.PERSISTED);
this.pageRecordCount++;
this.recordCount++;
return record;
} catch (final NoSuchElementException e) {
throw e;
} catch (final Throwable e) {
if (retry + 1 == maxRetries) {
throw new RuntimeException("Unable to read: " + getPathName(), e);
}
if (this.pageByObjectId) {
if (this.currentRecordId == previousRecordOffset) {
if (retry > 1) {
Logs.error(this, "Unable to read record: " + getPathName() + " " + this.idFieldName + "=" + (this.currentRecordId + 1));
this.currentRecordId++;
previousRecordOffset = this.currentRecordId;
}
} else {
Logs.error(this, "Unable to read record: " + getPathName() + " " + this.idFieldName + "=" + (this.currentRecordId + 1));
this.currentRecordId++;
}
} else {
close();
Exceptions.throwUncheckedException(e);
}
}
}
}
}
throw new RuntimeException("Unable to read: " + getPathName());
}
use of com.revolsys.record.io.format.json.JsonParser in project com.revolsys.open by revolsys.
the class ArcGisRestServerFeatureIterator method getNext.
@SuppressWarnings("resource")
@Override
protected Record getNext() throws NoSuchElementException {
int previousRecordOffset = this.currentRecordId;
final int maxRetries = 3;
for (int retry = 0; retry < maxRetries; retry++) {
if (this.closed) {
throw new NoSuchElementException();
} else {
JsonParser parser = this.parser;
if (this.recordCount < this.queryLimit) {
if (parser == null) {
parser = newParser();
}
if (!parser.skipToNextObjectInArray()) {
if (this.pageByObjectId) {
parser = newParser();
if (!parser.skipToNextObjectInArray()) {
throw new NoSuchElementException();
}
} else if (this.supportsPaging) {
if (this.pageRecordCount == this.pageSize) {
parser = newParser();
if (!parser.skipToNextObjectInArray()) {
throw new NoSuchElementException();
}
}
} else {
throw new NoSuchElementException();
}
}
} else {
throw new NoSuchElementException();
}
if (this.closed) {
throw new NoSuchElementException();
} else {
try {
if (parser.isEvent(EventType.endArray, EventType.endDocument)) {
throw new NoSuchElementException();
}
final MapEx recordMap = this.parser.getMap();
final Record record = this.recordFacory.newRecord(this.recordDefinition);
record.setState(RecordState.INITIALIZING);
final MapEx fieldValues = recordMap.getValue("attributes");
this.currentRecordId = fieldValues.getInteger(this.idFieldName, -1);
if (this.pageByObjectId) {
if (this.currentRecordId == -1) {
throw new NoSuchElementException();
}
}
record.setValues(fieldValues);
if (this.geometryConverter != null) {
final MapEx geometryProperties = recordMap.getValue("geometry");
if (Property.hasValue(geometryProperties)) {
final Geometry geometry = this.geometryConverter.apply(this.geometryFactory, geometryProperties);
record.setGeometryValue(geometry);
}
}
if (parser.hasNext()) {
final EventType nextEvent = parser.next();
if (nextEvent == EventType.endArray || nextEvent == EventType.endDocument) {
this.parser = null;
}
} else {
this.parser = null;
}
record.setState(RecordState.PERSISTED);
this.pageRecordCount++;
this.recordCount++;
return record;
} catch (final NoSuchElementException e) {
throw e;
} catch (final Throwable e) {
if (retry + 1 == maxRetries) {
throw new RuntimeException("Unable to read: " + getPathName(), e);
}
if (this.pageByObjectId) {
if (this.currentRecordId == previousRecordOffset) {
if (retry > 1) {
Logs.error(this, "Unable to read record: " + getPathName() + " " + this.idFieldName + "=" + (this.currentRecordId + 1));
this.currentRecordId++;
previousRecordOffset = this.currentRecordId;
}
} else {
Logs.error(this, "Unable to read record: " + getPathName() + " " + this.idFieldName + "=" + (this.currentRecordId + 1));
this.currentRecordId++;
}
} else {
close();
Exceptions.throwUncheckedException(e);
}
}
}
}
}
throw new RuntimeException("Unable to read: " + getPathName());
}
Aggregations