use of com.revolsys.record.io.format.json.JsonParser.EventType in project com.revolsys.open by revolsys.
the class GeoJsonGeometryReader method readCoordinatesListCoordinates.
/**
* Read one points coordinates and add them to the list of coordinate values.
*
* @param values The list to add the points coordinates to.
* @return The dimension of the coordinate read.
*/
private int readCoordinatesListCoordinates(final List<Double> values) {
int numAxis = 0;
if (this.in.getEvent() == EventType.startArray || this.in.hasNext() && this.in.next() == EventType.startArray) {
EventType event = this.in.getEvent();
do {
final JsonParser parser = this.in;
final Object value = parser.getValue();
if (value instanceof EventType) {
event = (EventType) value;
} else if (value instanceof Number) {
values.add(((Number) value).doubleValue());
numAxis++;
event = this.in.next();
} else {
throw new IllegalArgumentException("Expecting number, not: " + value);
}
} while (event == EventType.comma);
if (event != EventType.endArray) {
throw new IllegalStateException("Exepecting end array, not: " + event);
}
return numAxis;
} else {
throw new IllegalStateException("Exepecting start array, not: " + this.in.getEvent());
}
}
use of com.revolsys.record.io.format.json.JsonParser.EventType in project com.revolsys.open by revolsys.
the class GeoJsonGeometryReader method readGeometryList.
private List<Geometry> readGeometryList() {
if (this.in.getEvent() == EventType.startArray || this.in.hasNext() && this.in.next() == EventType.startArray) {
EventType event = this.in.next();
final List<Geometry> geometries = new ArrayList<>();
if (event != EventType.endArray) {
do {
final Geometry geometry = getNext();
geometries.add(geometry);
event = this.in.next();
} while (event == EventType.comma);
}
if (event != EventType.endArray) {
throw new IllegalStateException("Exepecting end array, not: " + event);
}
return geometries;
} else {
throw new IllegalStateException("Exepecting start array, not: " + this.in.getEvent());
}
}
use of com.revolsys.record.io.format.json.JsonParser.EventType 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.EventType 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