Search in sources :

Example 36 with DataStoreException

use of org.apache.sis.storage.DataStoreException in project sis by apache.

the class Store method close.

/**
 * Closes this data store and releases any underlying resources.
 *
 * @throws DataStoreException if an error occurred while closing this data store.
 */
@Override
public synchronized void close() throws DataStoreException {
    final Reader s = source;
    // Cleared first in case of failure.
    source = null;
    objects.clear();
    if (s != null)
        try {
            s.close();
        } catch (IOException e) {
            throw new DataStoreException(e);
        }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) Reader(java.io.Reader) IOException(java.io.IOException)

Example 37 with DataStoreException

use of org.apache.sis.storage.DataStoreException in project sis by apache.

the class MimeTypeDetector method probeContent.

/**
 * Wraps the call to {@link #getMimeType()} for catching {@link IOException} and for
 * instantiating the {@link ProbeResult}.
 */
final ProbeResult probeContent() throws DataStoreException {
    boolean isSupported = true;
    String mimeType;
    try {
        mimeType = getMimeType();
    } catch (IOException e) {
        throw new DataStoreException(e);
    }
    if (mimeType == null) {
        if (insufficientBytes) {
            return ProbeResult.INSUFFICIENT_BYTES;
        }
        isSupported = false;
        mimeType = StoreProvider.MIME_TYPE;
    }
    return new ProbeResult(isSupported, mimeType, null);
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) IOException(java.io.IOException) ProbeResult(org.apache.sis.storage.ProbeResult)

Example 38 with DataStoreException

use of org.apache.sis.storage.DataStoreException in project sis by apache.

the class Store method unmarshal.

/**
 * Unmarshal the object, if not already done. Note that {@link #object} may still be null
 * if an exception has been thrown at this invocation time or in previous invocation.
 *
 * @throws DataStoreException if an error occurred during the unmarshalling process.
 */
private void unmarshal() throws DataStoreException {
    final StreamSource s = source;
    final Closeable in = input(s);
    // Cleared first in case of error.
    source = null;
    if (in != null)
        try {
            try {
                object = XML.unmarshal(s, properties());
            } finally {
                in.close();
            }
        } catch (JAXBException | IOException e) {
            throw new DataStoreException(Errors.format(Errors.Keys.CanNotRead_1, getDisplayName()), e);
        }
    if (object instanceof CoordinateReferenceSystem)
        try {
            final DefinitionVerifier v = DefinitionVerifier.withAuthority((CoordinateReferenceSystem) object, null, false, getLocale());
            if (v != null) {
                log(v.warning(false));
            }
        } catch (FactoryException e) {
            listeners.warning(e);
        }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) FactoryException(org.opengis.util.FactoryException) StreamSource(javax.xml.transform.stream.StreamSource) Closeable(java.io.Closeable) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DefinitionVerifier(org.apache.sis.internal.referencing.DefinitionVerifier)

Example 39 with DataStoreException

use of org.apache.sis.storage.DataStoreException in project sis by apache.

the class Store method close.

/**
 * Closes this data store and releases any underlying resources.
 *
 * @throws DataStoreException if an error occurred while closing this data store.
 */
@Override
public synchronized void close() throws DataStoreException {
    final Reader r = reader;
    reader = null;
    if (r != null)
        try {
            r.close();
        } catch (Exception e) {
            final DataStoreException ds = new DataStoreException(e);
            try {
                super.close();
            } catch (DataStoreException s) {
                ds.addSuppressed(s.getCause());
            }
            throw ds;
        }
    super.close();
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) URISyntaxException(java.net.URISyntaxException) IllegalNameException(org.apache.sis.storage.IllegalNameException) DataStoreContentException(org.apache.sis.storage.DataStoreContentException) DataStoreException(org.apache.sis.storage.DataStoreException) BackingStoreException(org.apache.sis.util.collection.BackingStoreException) UncheckedIOException(java.io.UncheckedIOException) ConcurrentReadException(org.apache.sis.storage.ConcurrentReadException) FactoryException(org.opengis.util.FactoryException)

Aggregations

DataStoreException (org.apache.sis.storage.DataStoreException)39 IOException (java.io.IOException)16 DataStore (org.apache.sis.storage.DataStore)8 Path (java.nio.file.Path)6 DataStoreContentException (org.apache.sis.storage.DataStoreContentException)5 FeatureSet (org.apache.sis.storage.FeatureSet)5 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)4 IllegalNameException (org.apache.sis.storage.IllegalNameException)4 Resource (org.apache.sis.storage.Resource)4 BackingStoreException (org.apache.sis.util.collection.BackingStoreException)4 FactoryException (org.opengis.util.FactoryException)4 Reader (java.io.Reader)3 UncheckedIOException (java.io.UncheckedIOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 URISyntaxException (java.net.URISyntaxException)3 ByteBuffer (java.nio.ByteBuffer)3 ProbeResult (org.apache.sis.storage.ProbeResult)3 BufferedReader (java.io.BufferedReader)2 Closeable (java.io.Closeable)2 File (java.io.File)2