use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class ShapefileFeatureWriter method close.
/**
* Release resources and flush the header information.
*
* @throws IOException DOCUMENT ME!
*/
@Override
public void close() throws FeatureStoreRuntimeException {
if (featureReader == null) {
throw new FeatureStoreRuntimeException("Writer closed");
}
// make sure to write the last feature...
FeatureStoreRuntimeException wEx = null;
try {
if (currentFeature != null) {
write();
}
} catch (Throwable ex) {
wEx = new FeatureStoreRuntimeException(ex);
}
// before the end of the file
try {
if (attReader != null && attReader.hasNext()) {
shapeType = attReader.shp.getHeader().getShapeType();
handler = shapeType.getShapeHandler(true);
// stream is closed and the headers
if (records == 0) {
shpWriter.writeHeaders(bounds, shapeType, 0, 0);
}
// copy array for bounds
final double[] env = new double[4];
while (attReader.hasNext()) {
// transfer bytes from shapefile
shapefileLength += attReader.shp.transferTo(shpWriter, ++records, env);
// bounds update
bounds.expandToInclude(env[0], env[1]);
bounds.expandToInclude(env[2], env[3]);
// transfer dbf bytes
attReader.dbf.transferTo(dbfWriter);
}
}
} catch (IOException | DataStoreException ex) {
if (wEx == null) {
wEx = new FeatureStoreRuntimeException(ex);
} else {
wEx.addSuppressed(ex);
}
}
doClose();
try {
clean();
} catch (IOException ex) {
if (wEx == null) {
wEx = new FeatureStoreRuntimeException(ex);
} else {
wEx.addSuppressed(ex);
}
}
fireDataChangeEvents();
if (wEx != null) {
throw wEx;
}
}
use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class IndexedShapefileFeatureWriter method write.
@Override
public void write() throws FeatureStoreRuntimeException {
try {
fidWriter.write();
} catch (IOException ex) {
throw new FeatureStoreRuntimeException(ex);
}
// ensure the user did not modify the id between next() and write() calls
currentFeature.setPropertyValue(AttributeConvention.IDENTIFIER, currentFid);
super.write();
}
use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class IndexedFidReader method next.
@Override
public String next() throws FeatureStoreRuntimeException {
if (reader != null) {
try {
goTo(reader.getRecordNumber() - 1);
} catch (IOException ex) {
throw new FeatureStoreRuntimeException(ex);
}
}
if (!hasNext()) {
throw new NoSuchElementException("Feature could not be read; a the index may be invalid");
}
currentId = buffer.getLong();
currentShxIndex = buffer.getInt();
return typeName + currentId;
}
use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class CSVReader method next.
@Override
public Feature next() throws FeatureStoreRuntimeException {
read();
final Feature ob = current;
current = null;
if (ob == null) {
throw new FeatureStoreRuntimeException("No more records.");
}
return ob;
}
use of org.geotoolkit.storage.feature.FeatureStoreRuntimeException in project geotoolkit by Geomatys.
the class CSVWriter method write.
public void write() throws FeatureStoreRuntimeException {
if (edited == null || lastWritten == edited) {
return;
}
lastWritten = edited;
tempLock.writeLock().lock();
try {
int i = 0;
int n = atts.length;
for (PropertyType att : atts) {
final Object value = edited.getPropertyValue(att.getName().toString());
String str;
if (value == null) {
str = "";
} else if (AttributeConvention.isGeometryAttribute(att)) {
str = wktWriter.write((Geometry) value);
} else {
if (value instanceof Date) {
str = TemporalUtilities.toISO8601((Date) value);
} else if (value instanceof Boolean) {
str = value.toString();
} else if (value instanceof CharSequence) {
str = value.toString();
// escape strings
} else {
str = ObjectConverters.convert(value, String.class);
}
if (str != null) {
final boolean escape = str.indexOf('"') >= 0 || str.indexOf(';') >= 0 || str.indexOf('\n') >= 0;
if (escape) {
str = "\"" + str.replace("\"", "\"\"") + "\"";
}
}
}
writer.append(str);
if (i != n - 1) {
writer.append(store.getSeparator());
}
i++;
}
writer.append('\n');
writer.flush();
if (withId) {
if (appendMode) {
addedIds.add(FeatureExt.getId(edited));
} else {
updatedIds.add(FeatureExt.getId(edited));
}
}
} catch (IOException ex) {
throw new FeatureStoreRuntimeException(ex);
} finally {
tempLock.writeLock().unlock();
}
}
Aggregations