Search in sources :

Example 11 with FeatureStoreRuntimeException

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;
    }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException)

Example 12 with FeatureStoreRuntimeException

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();
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException)

Example 13 with FeatureStoreRuntimeException

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;
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Example 14 with FeatureStoreRuntimeException

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;
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Feature(org.opengis.feature.Feature)

Example 15 with FeatureStoreRuntimeException

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();
    }
}
Also used : FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) PropertyType(org.opengis.feature.PropertyType) IOException(java.io.IOException) Date(java.util.Date)

Aggregations

FeatureStoreRuntimeException (org.geotoolkit.storage.feature.FeatureStoreRuntimeException)35 DataStoreException (org.apache.sis.storage.DataStoreException)21 IOException (java.io.IOException)17 Feature (org.opengis.feature.Feature)16 HashMap (java.util.HashMap)8 FeatureType (org.opengis.feature.FeatureType)8 PropertyNotFoundException (org.opengis.feature.PropertyNotFoundException)5 PropertyType (org.opengis.feature.PropertyType)5 Path (java.nio.file.Path)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 FeatureSet (org.apache.sis.storage.FeatureSet)4 JAXPStreamFeatureWriter (org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter)4 Query (org.geotoolkit.storage.feature.query.Query)4 AttributeType (org.opengis.feature.AttributeType)4 ResourceId (org.opengis.filter.ResourceId)4 Date (java.util.Date)3 JAXBException (javax.xml.bind.JAXBException)3 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)3 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)3 GeoJSONStreamWriter (org.geotoolkit.storage.geojson.GeoJSONStreamWriter)3