sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1754632 - in /sis/branches/JDK8: core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ storage/s...
Date Sat, 30 Jul 2016 22:01:53 GMT
Author: desruisseaux
Date: Sat Jul 30 22:01:52 2016
New Revision: 1754632

URL: http://svn.apache.org/viewvc?rev=1754632&view=rev
Log:
Refactor TIFFException as DataStoreContentException and use it with other DataStores when
applicable.
First draft of ImageFileDirectory.completeMetadata(...), which complete the metadata with
information
available in IFD object. For now we just write the compression method, but more will be added
later.

Added:
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreContentException.java
      - copied, changed from r1754631, sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TIFFException.java
Removed:
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TIFFException.java
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Reader.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/HyperRectangleReader.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -94,7 +94,7 @@ import org.apache.sis.xml.Namespaces;
  * @author  Touraïvane (IRD)
  * @author  Cédric Briançon (Geomatys)
  * @since   0.3
- * @version 0.5
+ * @version 0.8
  * @module
  */
 @XmlType(name = "MD_Metadata_Type", propOrder = {
@@ -1265,7 +1265,7 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @XmlElement(name = "distributionInfo")
-    public Collection<? extends Distribution> getDistributionInfo() {
+    public Collection<Distribution> getDistributionInfo() {
         return distributionInfo = nonNullCollection(distributionInfo, Distribution.class);
     }
 

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -16,13 +16,15 @@
  */
 package org.apache.sis.storage.geotiff;
 
+import java.util.Locale;
 import java.io.IOException;
 import java.nio.charset.Charset;
 import org.opengis.metadata.Metadata;
 import org.apache.sis.setup.OptionKey;
 import org.apache.sis.storage.DataStore;
-import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStoreContentException;
 import org.apache.sis.internal.storage.ChannelDataInput;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
@@ -92,15 +94,17 @@ public class GeoTiffStore extends DataSt
     @Override
     public synchronized Metadata getMetadata() throws DataStoreException {
         if (metadata == null) try {
-            int index = 0;
-            while (reader.getImageFileDirectory(index) != null) {
-                index++;
+            int n = 0;
+            ImageFileDirectory dir;
+            final Locale locale = getLocale();
+            while ((dir = reader.getImageFileDirectory(n++)) != null) {
+                dir.completeMetadata(reader.metadata, locale);
             }
             metadata = reader.metadata.result();
         } catch (IOException e) {
-            throw new TIFFException(reader.errors().getString(Errors.Keys.CanNotRead_1, reader.input.filename),
e);
+            throw new DataStoreException(reader.errors().getString(Errors.Keys.CanNotRead_1,
reader.input.filename), e);
         } catch (ArithmeticException e) {
-            throw new TIFFException(reader.canNotDecode(), e);
+            throw new DataStoreContentException(reader.canNotDecode(), e);
         }
         return metadata;
     }

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -16,9 +16,11 @@
  */
 package org.apache.sis.storage.geotiff;
 
+import java.util.Locale;
 import java.io.IOException;
 import java.text.ParseException;
 import org.opengis.metadata.citation.DateType;
+import org.apache.sis.internal.storage.MetadataBuilder;
 
 
 /**
@@ -439,4 +441,14 @@ final class ImageFileDirectory {
         }
         return null;
     }
+
+    /**
+     * Completes the metadata with the information stored in the field of this IFD.
+     * This method is invoked only if the user requested the ISO 19115 metadata.
+     */
+    final void completeMetadata(final MetadataBuilder metadata, final Locale locale) {
+        if (compression != null) {
+            metadata.addCompression(compression.name().toLowerCase(locale));
+        }
+    }
 }

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Reader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Reader.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Reader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Reader.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -23,9 +23,10 @@ import java.util.Iterator;
 import java.io.IOException;
 import java.nio.ByteOrder;
 import java.text.ParseException;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStoreContentException;
 import org.apache.sis.internal.storage.ChannelDataInput;
 import org.apache.sis.internal.storage.MetadataBuilder;
-import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -98,6 +99,12 @@ final class Reader extends GeoTIFF {
     private final LinkedList<DeferredEntry> deferredEntries = new LinkedList<>();
 
     /**
+     * Whether {@link #deferredEntries} needs to be stored. This flag is set to {@code true}
when
+     * at least one new deferred entry has been added, and cleared after the sort has been
done.
+     */
+    private boolean deferredNeedsSort;
+
+    /**
      * Builder for the metadata.
      */
     final MetadataBuilder metadata;
@@ -156,7 +163,7 @@ final class Reader extends GeoTIFF {
             }
         }
         // Do not invoke errors() yet because GeoTiffStore construction may not be finished.
-        throw new TIFFException(Errors.format(Errors.Keys.UnexpectedFileFormat_2, "TIFF",
input.filename));
+        throw new DataStoreContentException(Errors.format(Errors.Keys.UnexpectedFileFormat_2,
"TIFF", input.filename));
     }
 
     /**
@@ -180,7 +187,7 @@ final class Reader extends GeoTIFF {
         if (pointer >= 0) {
             return pointer;
         }
-        throw new TIFFException(canNotDecode());
+        throw new DataStoreContentException(canNotDecode());
     }
 
     /**
@@ -197,7 +204,7 @@ final class Reader extends GeoTIFF {
         if (entry >= 0) {
             return entry;
         }
-        throw new TIFFException(canNotDecode());
+        throw new DataStoreContentException(canNotDecode());
     }
 
     /**
@@ -216,6 +223,7 @@ final class Reader extends GeoTIFF {
             if (nextIFD == 0) {
                 return null;
             }
+            resolveDeferredEntries(null, nextIFD);
             input.seek(Math.addExact(origin, nextIFD));
             nextIFD = 0;               // Prevent trying other IFD if we fail to read this
one.
             /*
@@ -264,6 +272,7 @@ final class Reader extends GeoTIFF {
                     // Offset from beginning of TIFF file where the values are stored.
                     deferredEntries.add(new DeferredEntry(dir, tag, type, count, readUnsignedInt()));
                     dir.hasDeferredEntries = true;
+                    deferredNeedsSort = true;
                 }
             }
             imageFileDirectories.add(dir);
@@ -278,35 +287,53 @@ final class Reader extends GeoTIFF {
          */
         final ImageFileDirectory dir = imageFileDirectories.get(index);
         if (dir.hasDeferredEntries) {
-            deferredEntries.sort(null);                                         // Sequential
order in input stream.
-            final long ignoreBefore = input.getStreamPosition() - origin;       // Avoid
seeking back, unless we need to.
-            DeferredEntry stopAfter = null;                                     // Avoid
reading more entries than needed.
-            Iterator<DeferredEntry> it = deferredEntries.descendingIterator();
-            while (it.hasNext()) {
+            resolveDeferredEntries(dir, Long.MAX_VALUE);
+            dir.hasDeferredEntries = false;
+        }
+        return dir;
+    }
+
+    /**
+     * Reads some of the entries that has been deferred. If the given {@code dir} argument
is non-null,
+     * then this method resolves all entries needed by this IFD no matter where the entry
value is located.
+     * For other entries, this method may opportunistically resolve some values but make
no guarantees.
+     * Generally, values of IFD other than {@code this} will not be resolved if they are
located before
+     * the current stream position or after the {@code ignoreAfter} value.
+     *
+     * @param dir  the IFD for which to resolve deferred entries regardless stream position
or {@code ignoreAfter} value.
+     * @param ignoreAfter  offset relative to the beginning of TIFF file at which entries
should be ignored.
+     *        This hint does not apply to the IFD specified by the {@code dir} argument.
+     */
+    private void resolveDeferredEntries(final ImageFileDirectory dir, final long ignoreAfter)
throws IOException {
+        if (deferredNeedsSort) {
+            deferredEntries.sort(null);                                 // Sequential order
in input stream.
+            deferredNeedsSort = false;
+        }
+        final long ignoreBefore = input.getStreamPosition() - origin;   // Avoid seeking
back, unless we need to.
+        DeferredEntry stopAfter = null;                                 // Avoid reading
more entries than needed.
+        if (dir != null) {
+            for (final Iterator<DeferredEntry> it = deferredEntries.descendingIterator();
it.hasNext();) {
                 stopAfter = it.next();
                 if (stopAfter.owner == dir) break;
             }
-            it = deferredEntries.iterator();
-            while (it.hasNext()) {
-                final DeferredEntry entry = it.next();
-                if (entry.owner == dir || entry.offset >= ignoreBefore) {
-                    input.seek(Math.addExact(origin, entry.offset));
-                    Object error;
-                    try {
-                        error = entry.owner.addEntry(this, entry.tag, entry.type, entry.count);
-                    } catch (ParseException | RuntimeException e) {
-                        error = e;
-                    }
-                    if (error != null) {
-                        warning(entry.tag, error);
-                    }
-                    it.remove();            // Remove only on success, but before we try
to read other entries.
+        }
+        for (final Iterator<DeferredEntry> it = deferredEntries.iterator(); it.hasNext();)
{
+            final DeferredEntry entry = it.next();
+            if (entry.owner == dir || (entry.offset >= ignoreBefore && entry.offset
<= ignoreAfter)) {
+                input.seek(Math.addExact(origin, entry.offset));
+                Object error;
+                try {
+                    error = entry.owner.addEntry(this, entry.tag, entry.type, entry.count);
+                } catch (ParseException | RuntimeException e) {
+                    error = e;
+                }
+                if (error != null) {
+                    warning(entry.tag, error);
                 }
-                if (entry == stopAfter) break;
+                it.remove();            // Remove only on success, but before we try to read
other entries.
             }
-            dir.hasDeferredEntries = false;
+            if (entry == stopAfter) break;
         }
-        return dir;
     }
 
     /**

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -40,6 +40,7 @@ import org.apache.sis.internal.netcdf.Gr
 import org.apache.sis.internal.storage.ChannelDataInput;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStoreContentException;
 import org.apache.sis.util.iso.DefaultNameSpace;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Vocabulary;
@@ -60,7 +61,7 @@ import java.util.function.Function;
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  *
  * @see <a href="http://portal.opengeospatial.org/files/?artifact_id=43734">NetCDF
Classic and 64-bit Offset Format (1.0)</a>
@@ -202,7 +203,7 @@ public final class ChannelDecoder extend
          */
         int version = input.readInt();
         if ((version & 0xFFFFFF00) != MAGIC_NUMBER) {
-            throw new DataStoreException(errors().getString(Errors.Keys.UnexpectedFileFormat_2,
"NetCDF", input.filename));
+            throw new DataStoreContentException(errors().getString(Errors.Keys.UnexpectedFileFormat_2,
"NetCDF", input.filename));
         }
         /*
          * Check the version number.
@@ -211,7 +212,7 @@ public final class ChannelDecoder extend
         switch (version) {
             case 1:  is64bits = false; break;
             case 2:  is64bits = true;  break;
-            default: throw new DataStoreException(errors().getString(Errors.Keys.UnsupportedVersion_1,
version));
+            default: throw new DataStoreContentException(errors().getString(Errors.Keys.UnsupportedVersion_1,
version));
             // If more cases are added, remember to increment the MAX_VERSION constant.
         }
         numrecs = input.readInt();
@@ -272,7 +273,7 @@ public final class ChannelDecoder extend
      * that the file should be a NetCDF one, but we found some inconsistency or unknown tags.
      */
     private DataStoreException malformedHeader() {
-        return new DataStoreException(errors().getString(Errors.Keys.CanNotParseFile_2, "NetCDF",
input.filename));
+        return new DataStoreContentException(errors().getString(Errors.Keys.CanNotParseFile_2,
"NetCDF", input.filename));
     }
 
     /**
@@ -280,7 +281,7 @@ public final class ChannelDecoder extend
      */
     private void ensureNonNegative(final int nelems, final int tag) throws DataStoreException
{
         if (nelems < 0) {
-            throw new DataStoreException(errors().getString(Errors.Keys.NegativeArrayLength_1,
+            throw new DataStoreContentException(errors().getString(Errors.Keys.NegativeArrayLength_1,
                     input.filename + DefaultNameSpace.DEFAULT_SEPARATOR + tagName(tag)));
         }
     }
@@ -305,7 +306,7 @@ public final class ChannelDecoder extend
         if (size > input.buffer.capacity()) {
             name = input.filename + DefaultNameSpace.DEFAULT_SEPARATOR + name;
             final Errors errors = errors();
-            throw new DataStoreException(n < 0 ?
+            throw new DataStoreContentException(n < 0 ?
                     errors.getString(Errors.Keys.NegativeArrayLength_1, name) :
                     errors.getString(Errors.Keys.ExcessiveListSize_2, name, n));
         }
@@ -416,7 +417,7 @@ public final class ChannelDecoder extend
             if (length == 0) {
                 length = numrecs;
                 if (length == STREAMING) {
-                    throw new DataStoreException(errors().getString(Errors.Keys.MissingValueForProperty_1,
"numrecs"));
+                    throw new DataStoreContentException(errors().getString(Errors.Keys.MissingValueForProperty_1,
"numrecs"));
                 }
             }
             dimensions[i] = new Dimension(name, length);
@@ -535,7 +536,7 @@ public final class ChannelDecoder extend
         try {
             return CollectionsExt.toCaseInsensitiveNameMap(Arrays.asList(elements), nameFunction,
NAME_LOCALE);
         } catch (InvalidParameterCardinalityException e) {
-            throw new DataStoreException(errors().getString(Errors.Keys.ValueAlreadyDefined_1,
e.getParameterName()));
+            throw new DataStoreContentException(errors().getString(Errors.Keys.ValueAlreadyDefined_1,
e.getParameterName()));
         }
     }
 

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -26,6 +26,7 @@ import org.apache.sis.internal.storage.C
 import org.apache.sis.internal.storage.HyperRectangleReader;
 import org.apache.sis.internal.storage.Region;
 import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStoreContentException;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.Numbers;
 
@@ -36,7 +37,7 @@ import org.apache.sis.util.Numbers;
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.7
+ * @version 0.8
  * @module
  */
 final class VariableInfo extends Variable {
@@ -309,14 +310,14 @@ final class VariableInfo extends Variabl
     @Override
     public Object read() throws IOException, DataStoreException {
         if (reader == null) {
-            throw new DataStoreException(unknownType());
+            throw new DataStoreContentException(unknownType());
         }
         long length = 1;
         for (final Dimension dimension : dimensions) {
             length *= dimension.length;
         }
         if (length > Integer.MAX_VALUE) {
-            throw new DataStoreException(Errors.format(Errors.Keys.ExcessiveListSize_2, name,
length));
+            throw new DataStoreContentException(Errors.format(Errors.Keys.ExcessiveListSize_2,
name, length));
         }
         final int dimension = dimensions.length;
         final long[] size  = new long[dimension];
@@ -339,7 +340,7 @@ final class VariableInfo extends Variabl
     @Override
     public Object read(int[] areaLower, int[] areaUpper, int[] subsampling) throws IOException,
DataStoreException {
         if (reader == null) {
-            throw new DataStoreException(unknownType());
+            throw new DataStoreContentException(unknownType());
         }
         /*
          * NetCDF sorts datas in reverse dimension order. Example:

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -26,6 +26,7 @@ import ucar.nc2.Dimension;
 import ucar.nc2.VariableIF;
 import org.apache.sis.internal.netcdf.Variable;
 import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStoreContentException;
 
 
 /**
@@ -34,7 +35,7 @@ import org.apache.sis.storage.DataStoreE
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Johann Sorel (Geomatys)
  * @since   0.3
- * @version 0.7
+ * @version 0.8
  * @module
  */
 final class VariableWrapper extends Variable {
@@ -206,7 +207,7 @@ final class VariableWrapper extends Vari
         try {
             array = variable.read(new Section(areaLower, size, subsampling));
         } catch (InvalidRangeException e) {
-            throw new DataStoreException(e);
+            throw new DataStoreContentException(e);
         }
         return array.get1DJavaArray(array.getElementType());
     }

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -24,6 +24,7 @@ import org.apache.sis.util.ArgumentCheck
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.storage.DataStore;
 import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStoreContentException;
 import org.apache.sis.storage.StorageConnector;
 import org.apache.sis.internal.netcdf.Decoder;
 import org.apache.sis.metadata.ModifiableMetadata;
@@ -68,7 +69,7 @@ public class NetcdfStore extends DataSto
             throw new DataStoreException(e);
         }
         if (decoder == null) {
-            throw new DataStoreException(Errors.format(Errors.Keys.IllegalInputTypeForReader_2,
+            throw new DataStoreContentException(Errors.format(Errors.Keys.IllegalInputTypeForReader_2,
                     "NetCDF", Classes.getClass(storage.getStorage())));
         }
     }

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -120,7 +120,7 @@ public class NetcdfStoreProvider extends
      * only that there appears to be a reasonable chance of success based on a brief inspection
of the
      * {@linkplain StorageConnector#getStorage() storage object} or contents.
      *
-     * @param  storage Information about the storage (URL, stream, {@link ucar.nc2.NetcdfFile}
instance, <i>etc</i>).
+     * @param  storage  information about the storage (URL, stream, {@link ucar.nc2.NetcdfFile}
instance, <i>etc</i>).
      * @return {@code SUPPORTED} if the given storage seems to be usable by the {@code NetcdfStore}
instances.
      * @throws DataStoreException if an I/O error occurred.
      */
@@ -174,7 +174,7 @@ public class NetcdfStoreProvider extends
                         Logging.recoverableException(Logging.getLogger(Modules.NETCDF), netcdfFileClass,
"canOpen", cause);
                         return ProbeResult.UNSUPPORTED_STORAGE;
                     }
-                    throw new DataStoreException(e); // The cause may be IOException.
+                    throw new DataStoreException(e);                        // The cause
may be IOException.
                 }
             } else {
                 /*
@@ -203,8 +203,8 @@ public class NetcdfStoreProvider extends
     /**
      * Returns a {@link NetcdfStore} implementation associated with this provider.
      *
-     * @param  storage Information about the storage (URL, stream, {@link ucar.nc2.NetcdfFile}
instance, <i>etc</i>).
-     * @return A data store implementation associated with this provider for the given storage.
+     * @param  storage information about the storage (URL, stream, {@link ucar.nc2.NetcdfFile}
instance, <i>etc</i>).
+     * @return a data store implementation associated with this provider for the given storage.
      * @throws DataStoreException if an error occurred while creating the data store instance.
      */
     @Override
@@ -216,9 +216,9 @@ public class NetcdfStoreProvider extends
      * Creates a decoder for the given input. This method invokes
      * {@link StorageConnector#closeAllExcept(Object)} after the decoder has been created.
      *
-     * @param  listeners Where to send the warnings.
-     * @param  storage Information about the input (file, input stream, <i>etc.</i>)
-     * @return The decoder for the given input, or {@code null} if the input type is not
recognized.
+     * @param  listeners  where to send the warnings.
+     * @param  storage    information about the input (file, input stream, <i>etc.</i>)
+     * @return the decoder for the given input, or {@code null} if the input type is not
recognized.
      * @throws IOException if an error occurred while opening the NetCDF file.
      * @throws DataStoreException if a logical error (other than I/O) occurred.
      */
@@ -253,11 +253,11 @@ public class NetcdfStoreProvider extends
      * not create our embedded NetCDF decoder. This method uses reflection for creating the
wrapper, in order
      * to keep the UCAR dependency optional.
      *
-     * @param  listeners Where to send the warnings.
-     * @param  input  The NetCDF file object of filename string from which to read data.
-     * @param  isUCAR {@code true} if {@code input} is an instance of the UCAR {@link ucar.nc2.NetcdfFile}
object,
-     *                or {@code false} if it is the filename as a {@code String}.
-     * @return The {@link DecoderWrapper} instance for the given input, or {@code null} if
the input type is not recognized.
+     * @param  listeners  where to send the warnings.
+     * @param  input      the NetCDF file object of filename string from which to read data.
+     * @param  isUCAR     {@code true} if {@code input} is an instance of the UCAR {@link
ucar.nc2.NetcdfFile} object,
+     *                    or {@code false} if it is the filename as a {@code String}.
+     * @return the {@link DecoderWrapper} instance for the given input, or {@code null} if
the input type is not recognized.
      * @throws IOException if an error occurred while opening the NetCDF file.
      * @throws DataStoreException if a logical error (other than I/O) occurred.
      */
@@ -327,7 +327,7 @@ public class NetcdfStoreProvider extends
                     parameterTypes[1] = String.class;
                     createFromPath = wrapper.getConstructor(parameterTypes);
                 } catch (ReflectiveOperationException e) {
-                    throw new AssertionError(e); // Should never happen (shall be verified
by the JUnit tests).
+                    throw new AssertionError(e);        // Should never happen (shall be
verified by the JUnit tests).
                 }
             }
         }

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/HyperRectangleReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/HyperRectangleReader.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/HyperRectangleReader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/HyperRectangleReader.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -22,6 +22,7 @@ import java.io.IOException;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStoreContentException;
 import org.apache.sis.util.Debug;
 
 
@@ -33,7 +34,7 @@ import org.apache.sis.util.Debug;
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
- * @version 0.7
+ * @version 0.8
  * @module
  */
 public final class HyperRectangleReader {
@@ -66,7 +67,7 @@ public final class HyperRectangleReader
             case Numbers.LONG:      reader = input.new LongsReader  ((long[])   null); break;
             case Numbers.FLOAT:     reader = input.new FloatsReader ((float[])  null); break;
             case Numbers.DOUBLE:    reader = input.new DoublesReader((double[]) null); break;
-            default: throw new DataStoreException(Errors.format(Errors.Keys.UnknownType_1,
dataType));
+            default: throw new DataStoreContentException(Errors.format(Errors.Keys.UnknownType_1,
dataType));
         }
         this.origin = origin;
         final ByteBuffer buffer = input.buffer;

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -39,6 +39,8 @@ import org.apache.sis.metadata.iso.citat
 import org.apache.sis.metadata.iso.citation.DefaultResponsibility;
 import org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints;
 import org.apache.sis.metadata.iso.identification.DefaultDataIdentification;
+import org.apache.sis.metadata.iso.distribution.DefaultDistribution;
+import org.apache.sis.metadata.iso.distribution.DefaultFormat;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.iso.Types;
@@ -109,6 +111,16 @@ public class MetadataBuilder {
     private DefaultSampleDimension sampleDimension;
 
     /**
+     * The distribution format, or {@code null} if none.
+     */
+    private DefaultFormat format;
+
+    /**
+     * Information about distribution (including the {@linkplain #format}), or {@code null}
if none.
+     */
+    private DefaultDistribution distribution;
+
+    /**
      * Creates a new metadata reader.
      */
     public MetadataBuilder() {
@@ -172,6 +184,14 @@ public class MetadataBuilder {
             metadata().getIdentificationInfo().add(identification);
             identification = null;
         }
+        if (format != null) {
+            distribution().getDistributionFormats().add(format);
+            format = null;
+        }
+        if (distribution != null) {
+            metadata().getDistributionInfo().add(distribution);
+            distribution = null;
+        }
     }
 
     /**
@@ -298,6 +318,30 @@ public class MetadataBuilder {
     }
 
     /**
+     * Creates the distribution format object if it does not already exists, then return
it.
+     *
+     * @return the distribution format (never {@code null}).
+     */
+    private DefaultFormat format() {
+        if (format == null) {
+            format = new DefaultFormat();
+        }
+        return format;
+    }
+
+    /**
+     * Creates the distribution information object if it does not already exists, then return
it.
+     *
+     * @return the distribution information (never {@code null}).
+     */
+    private DefaultDistribution distribution() {
+        if (distribution == null) {
+            distribution = new DefaultDistribution();
+        }
+        return distribution;
+    }
+
+    /**
      * Adds the given character encoding to the metadata.
      *
      * @param encoding  the character encoding to add.
@@ -673,4 +717,17 @@ parse:      for (int i = 0; i < length;)
             }
         }
     }
+
+    /**
+     * Adds a compression name.
+     *
+     * @param value  the compression name, or {@code null}.
+     */
+    public final void addCompression(final CharSequence value) {
+        final InternationalString i18n = trim(value);
+        if (i18n != null) {
+            final DefaultFormat format = format();
+            format.setFileDecompressionTechnique(append(format.getFileDecompressionTechnique(),
i18n));
+        }
+    }
 }

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -50,6 +50,7 @@ import org.apache.sis.geometry.GeneralEn
 import org.apache.sis.metadata.iso.DefaultMetadata;
 import org.apache.sis.storage.DataStore;
 import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStoreContentException;
 import org.apache.sis.storage.StorageConnector;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.CharSequences;
@@ -205,14 +206,14 @@ public final class Store extends DataSto
                 switch (keyword.toLowerCase(Locale.US)) {
                     case "@stboundedby": {
                         if (envelope != null) {
-                            throw new DataStoreException(duplicated("@stboundedby"));
+                            throw new DataStoreContentException(duplicated("@stboundedby"));
                         }
                         envelope = parseEnvelope(elements);
                         break;
                     }
                     case "@columns": {
                         if (featureType != null) {
-                            throw new DataStoreException(duplicated("@columns"));
+                            throw new DataStoreContentException(duplicated("@columns"));
                         }
                         featureType = parseFeatureType(elements);
                         if (foliation == null) {
@@ -222,7 +223,7 @@ public final class Store extends DataSto
                     }
                     case "@foliation": {
                         if (foliation != null) {
-                            throw new DataStoreException(duplicated("@foliation"));
+                            throw new DataStoreContentException(duplicated("@foliation"));
                         }
                         foliation = parseFoliation(elements);
                         break;
@@ -282,7 +283,7 @@ public final class Store extends DataSto
                         case "hour":     timeUnit = NonSI.HOUR;   break;
                         case "day":      timeUnit = NonSI.DAY;    break;
                         case "absolute": isTimeAbsolute = true;   break;
-                        default: throw new DataStoreException(errors().getString(Errors.Keys.UnknownUnit_1,
unit));
+                        default: throw new DataStoreContentException(errors().getString(Errors.Keys.UnknownUnit_1,
unit));
                     }
                     // Fall through
             case 7: endTime     = Instant      .parse(       elements.get(6));
@@ -294,7 +295,7 @@ public final class Store extends DataSto
                         case "":   // Default to 2D.
                         case "2D": break;
                         case "3D": is3D = true; break;
-                        default: throw new DataStoreException(errors().getString(
+                        default: throw new DataStoreContentException(errors().getString(
                                         Errors.Keys.IllegalCoordinateSystem_1, dimension));
                     }
                     // Fall through
@@ -345,7 +346,7 @@ public final class Store extends DataSto
                 if ((dim = lowerCorner.length) != spatialDimension ||
                     (dim = upperCorner.length) != spatialDimension)
                 {
-                    throw new DataStoreException(errors().getString(
+                    throw new DataStoreContentException(errors().getString(
                             Errors.Keys.MismatchedDimension_2, dim, spatialDimension));
                 }
                 for (int i=0; i<spatialDimension; i++) {
@@ -389,7 +390,7 @@ public final class Store extends DataSto
                         case "string":   type = String .class; break;
                         case "datetime": type = Instant.class; break;
                         case "anyuri":   type = URI    .class; break;
-                        default: throw new DataStoreException(errors().getString(Errors.Keys.UnknownType_1,
tn));
+                        default: throw new DataStoreContentException(errors().getString(Errors.Keys.UnknownType_1,
tn));
                     }
                 }
             }
@@ -469,7 +470,7 @@ public final class Store extends DataSto
             try {
                 builder.add(envelope);
             } catch (TransformException e) {
-                throw new DataStoreException(errors().getString(Errors.Keys.CanNotParseFile_2,
"CSV", name), e);
+                throw new DataStoreContentException(errors().getString(Errors.Keys.CanNotParseFile_2,
"CSV", name), e);
             }
             metadata = builder.result();
         }

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java?rev=1754632&r1=1754631&r2=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -32,6 +32,7 @@ import org.apache.sis.io.wkt.Warnings;
 import org.apache.sis.storage.DataStore;
 import org.apache.sis.storage.StorageConnector;
 import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStoreContentException;
 import org.apache.sis.metadata.iso.DefaultMetadata;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.CharSequences;
@@ -44,7 +45,7 @@ import org.apache.sis.referencing.CRS;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
- * @version 0.7
+ * @version 0.8
  * @module
  */
 final class Store extends DataStore {
@@ -103,7 +104,7 @@ final class Store extends DataStore {
                 while ((n = in.read(buffer, length, buffer.length - length)) >= 0) {
                     if ((length += n) >= buffer.length) {
                         if (n >= Integer.MAX_VALUE / 1024) {     // Arbitrary size limit.
-                            throw new DataStoreException(Errors.format(Errors.Keys.ExcessiveStringSize));
+                            throw new DataStoreContentException(Errors.format(Errors.Keys.ExcessiveStringSize));
                         }
                         buffer = Arrays.copyOf(buffer, n << 1);
                     }

Copied: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreContentException.java
(from r1754631, sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TIFFException.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreContentException.java?p2=sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreContentException.java&p1=sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TIFFException.java&r1=1754631&r2=1754632&rev=1754632&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TIFFException.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreContentException.java
[UTF-8] Sat Jul 30 22:01:52 2016
@@ -14,20 +14,26 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.storage.geotiff;
-
-import org.apache.sis.storage.DataStoreException;
+package org.apache.sis.storage;
 
 
 /**
- * Thrown when a TIFF file can not be read because of a logical inconsistency.
+ * Thrown when a store can not be read because the stream contains invalid data.
+ * It may be for example a logical inconsistency, or a reference not found,
+ * or an unsupported file format version, <i>etc.</i>
+ *
+ * <div class="note"><b>Note:</b>
+ * exceptions that are caused by {@link java.io.IOException} or {@link java.sql.SQLException}
+ * should generally be wrapped by another type of {@link DataStoreException}, unless the
data
+ * store can determine that the error was caused by a problem with the stream content rather
+ * than some I/O problems.</div>
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.8
  * @version 0.8
  * @module
  */
-public class TIFFException extends DataStoreException {
+public class DataStoreContentException extends DataStoreException {
     /**
      * For cross-version compatibility.
      */
@@ -38,17 +44,26 @@ public class TIFFException extends DataS
      *
      * @param message  the detail message.
      */
-    public TIFFException(String message) {
+    public DataStoreContentException(String message) {
         super(message);
     }
 
     /**
+     * Creates an exception with the specified cause.
+     *
+     * @param cause  the cause for this exception.
+     */
+    public DataStoreContentException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
      * Creates an exception with the specified details message and cause.
      *
      * @param message  the detail message.
      * @param cause    the cause for this exception.
      */
-    public TIFFException(String message, final Throwable cause) {
+    public DataStoreContentException(String message, Throwable cause) {
         super(message, cause);
     }
 }




Mime
View raw message