sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1733845 - in /sis/branches/JDK8/storage: sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/ sis-netcdf/src/te...
Date Sun, 06 Mar 2016 22:01:07 GMT
Author: desruisseaux
Date: Sun Mar  6 22:01:07 2016
New Revision: 1733845

URL: http://svn.apache.org/viewvc?rev=1733845&view=rev
Log:
Use HyperRectangleReader in NetCDF data store.

Modified:
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.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/Dimension.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/test/java/org/apache/sis/internal/netcdf/DecoderTest.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.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/storage/StorageConnector.java

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -27,8 +27,9 @@ import org.apache.sis.util.Debug;
  * A NetCDF variable created by {@link Decoder}.
  *
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Johann Sorel (Geomatys)
  * @since   0.3
- * @version 0.5
+ * @version 0.7
  * @module
  */
 public abstract class Variable {
@@ -151,7 +152,7 @@ public abstract class Variable {
      * @return {@code true} if the variable can be considered a coverage.
      */
     public final boolean isCoverage(final int minSpan) {
-        int numVectors = 0; // Number of dimension having more than 1 value.
+        int numVectors = 0;                                     // Number of dimension having
more than 1 value.
         for (final int length : getGridEnvelope()) {
             if (Integer.toUnsignedLong(length) >= minSpan) {
                 numVectors++;
@@ -164,9 +165,8 @@ public abstract class Variable {
     }
 
     /**
-     * Returns {@code true} if this variable seems to be a coordinate system axis instead
than
-     * the actual data. By NetCDF convention, coordinate system axes have the name of one
of the
-     * dimensions defined in the NetCDF header.
+     * Returns {@code true} if this variable seems to be a coordinate system axis instead
than the actual data.
+     * By NetCDF convention, coordinate system axes have the name of one of the dimensions
defined in the NetCDF header.
      *
      * @return {@code true} if this variable seems to be a coordinate system axis.
      */
@@ -206,12 +206,31 @@ public abstract class Variable {
      * Reads all the data for this variable and returns them as an array of a Java primitive
type.
      *
      * @return The data as an array of a Java primitive type.
-     * @throws IOException If an error occurred while reading the data.
-     * @throws DataStoreException If a logical error occurred.
+     * @throws IOException if an error occurred while reading the data.
+     * @throws DataStoreException if a logical error occurred.
      */
     public abstract Object read() throws IOException, DataStoreException;
 
     /**
+     * Reads a sub-sampled sub-area of the variable.
+     * Constraints on the argument values are:
+     *
+     * <ul>
+     *   <li>All arrays length shall be equal to the length of the {@link #getGridEnvelope()}
array.</li>
+     *   <li>For each index <var>i</var>, value of {@code area[i]} shall
be in the range from 0 inclusive
+     *       to {@code Integer.toUnsignedLong(getGridEnvelope()[i])} exclusive.</li>
+     * </ul>
+     *
+     * @param  areaLower   Index of the first value to read along each dimension.
+     * @param  areaUpper   Index after the last value to read along each dimension.
+     * @param  subsampling Sub-sampling along each dimension. 1 means no sub-sampling.
+     * @return The data as an array of a Java primitive type.
+     * @throws IOException if an error occurred while reading the data.
+     * @throws DataStoreException if a logical error occurred.
+     */
+    public abstract Object read(int[] areaLower, int[] areaUpper, int[] subsampling) throws
IOException, DataStoreException;
+
+    /**
      * Returns a string representation of this variable for debugging purpose.
      *
      * @return A string representation of this variable.

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=1733845&r1=1733844&r2=1733845&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] Sun Mar  6 22:01:07 2016
@@ -681,6 +681,7 @@ public final class ChannelDecoder extend
      * @throws IOException {@inheritDoc}
      */
     @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
     public Variable[] getVariables() throws IOException {
         return variables;
     }
@@ -693,6 +694,7 @@ public final class ChannelDecoder extend
      * @throws IOException {@inheritDoc}
      */
     @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
     public GridGeometry[] getGridGeometries() throws IOException {
         if (gridGeometries == null) {
             /*

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/Dimension.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/Dimension.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/Dimension.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/Dimension.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -27,9 +27,8 @@ import org.apache.sis.util.Debug;
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.7
  * @module
- *
  */
 final class Dimension {
     /**
@@ -38,12 +37,15 @@ final class Dimension {
     final String name;
 
     /**
-     * The number of grid cell value along that dimension, as an unsigned number.
+     * The number of grid cell value along this dimension, as an unsigned number.
      */
     final int length;
 
     /**
      * Creates a new dimension of the given name and length.
+     *
+     * @param name   The dimension name.
+     * @param length The number of grid cell value along this dimension, as an unsigned number.
      */
     Dimension(final String name, final int length) {
         this.name   = name;
@@ -51,11 +53,18 @@ final class Dimension {
     }
 
     /**
+     * Returns the number of grid cell value along this dimension.
+     */
+    final long length() {
+        return Integer.toUnsignedLong(length);
+    }
+
+    /**
      * A string representation of this dimension for debugging purpose only.
      */
     @Debug
     @Override
     public String toString() {
-        return name + '[' + Integer.toUnsignedLong(length) + ']';
+        return name + '[' + length() + ']';
     }
 }

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=1733845&r1=1733844&r2=1733845&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] Sun Mar  6 22:01:07 2016
@@ -23,8 +23,11 @@ import ucar.nc2.constants.CDM;
 import ucar.nc2.constants._Coordinate;
 import org.apache.sis.internal.netcdf.Variable;
 import org.apache.sis.internal.storage.ChannelDataInput;
+import org.apache.sis.internal.storage.HyperRectangleReader;
+import org.apache.sis.internal.storage.Region;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.Numbers;
 
 
 /**
@@ -33,7 +36,7 @@ import org.apache.sis.util.resources.Err
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.5
+ * @version 0.7
  * @module
  */
 final class VariableInfo extends Variable {
@@ -49,19 +52,31 @@ final class VariableInfo extends Variabl
     };
 
     /**
-     * The type of data. Number of bits and endianness are same as in the Java language
-     * except {@code CHAR}, which is defined as an unsigned 8-bits value.
+     * The NetCDF type of data. Number of bits and endianness are same as in the Java language
except {@code CHAR},
+     * which is defined as an unsigned 8-bits value.
      */
     static final int BYTE=1, CHAR=2, SHORT=3, INT=4, FLOAT=5, DOUBLE=6;
 
     /**
+     * Mapping from the NetCDF data type to the enumeration used by our {@link Numbers} class.
+     */
+    private static final byte[] NUMBER_TYPES = new byte[] {
+        Numbers.BYTE,
+        Numbers.BYTE,       // NOT Numbers.CHARACTER
+        Numbers.SHORT,
+        Numbers.INTEGER,
+        Numbers.FLOAT,
+        Numbers.DOUBLE,
+    };
+
+    /**
      * The size in bytes of the above constants.
      *
      * @see #sizeOf(int)
      */
-    private static final int[] SIZES = new int[] {
+    private static final byte[] SIZES = new byte[] {
         Byte   .BYTES,
-        Byte   .BYTES, // NOT Java char
+        Byte   .BYTES,      // NOT Character.BYTES
         Short  .BYTES,
         Integer.BYTES,
         Float  .BYTES,
@@ -83,11 +98,10 @@ final class VariableInfo extends Variabl
     };
 
     /**
-     * The channel together with a buffer for reading the variable data.
-     *
-     * @see #read()
+     * Helper class for reading a sub-area with a sub-sampling,
+     * or {@code null} if {@code dataType} is not a supported type.
      */
-    private final ChannelDataInput input;
+    private final HyperRectangleReader reader;
 
     /**
      * The variable name.
@@ -95,7 +109,7 @@ final class VariableInfo extends Variabl
     private final String name;
 
     /**
-     * The dimensions of that variable.
+     * The dimensions of this variable.
      */
     final Dimension[] dimensions;
 
@@ -110,15 +124,9 @@ final class VariableInfo extends Variabl
     private final Map<String,Attribute> attributes;
 
     /**
-     * The type of data, as one of the {@code BYTE}, {@code SHORT} and similar constants
defined
-     * in {@link ChannelDecoder}.
+     * The type of data, as one of the {@code BYTE}, {@code SHORT} and similar constants
defined in this class.
      */
-    private final int datatype;
-
-    /**
-     * The offset where the variable data begins in the NetCDF file.
-     */
-    private final long offset;
+    private final int dataType;
 
     /**
      * The grid geometry associated to this variable,
@@ -128,22 +136,35 @@ final class VariableInfo extends Variabl
 
     /**
      * Creates a new variable.
+     *
+     * @param input         The channel together with a buffer for reading the variable data.
+     * @param name          The variable name.
+     * @param dimensions    The dimensions of this variable.
+     * @param allDimensions All dimensions in the NetCDF files.
+     * @param attributes    The attributes associates to the variable, or an empty map if
none.
+     * @param dataType      The type of data, as one of the {@code BYTE} and similar constants
defined in this class.
+     * @param size          The variable size, used for verification purpose only.
+     * @param offset        The offset where the variable data begins in the NetCDF file.
      */
     VariableInfo(final ChannelDataInput input, final String name,
             final Dimension[] dimensions, final Dimension[] allDimensions,
-            final Map<String,Attribute> attributes, final int datatype, final int size,
final long offset)
+            final Map<String,Attribute> attributes, int dataType, final int size, final
long offset)
+            throws DataStoreException
     {
-        this.input         = input;
         this.name          = name;
         this.dimensions    = dimensions;
         this.allDimensions = allDimensions;
         this.attributes    = attributes;
-        this.datatype      = datatype;
-        this.offset        = offset;
+        this.dataType      = dataType;
         /*
          * The 'size' value is provided in the NetCDF files, but doesn't need to be stored
since it
          * is redundant with the dimension lengths and is not large enough for big variables
anyway.
          */
+        if (--dataType >= 0 && dataType < NUMBER_TYPES.length) {
+            reader = new HyperRectangleReader(NUMBER_TYPES[dataType], input, offset);
+        } else {
+            reader = null;
+        }
     }
 
     /**
@@ -188,7 +209,7 @@ final class VariableInfo extends Variabl
      */
     @Override
     public Class<?> getDataType() {
-        final int i = datatype - 1;
+        final int i = dataType - 1;
         return (i >= 0 && i < TYPES.length) ? TYPES[i] : null;
     }
 
@@ -256,6 +277,8 @@ final class VariableInfo extends Variabl
     /**
      * Returns the length (number of cells) of each grid dimension. In ISO 19123 terminology,
this method
      * returns the upper corner of the grid envelope plus one. The lower corner is always
(0,0,…,0).
+     *
+     * @return The number of grid cells for each dimension, as unsigned integers.
      */
     @Override
     public int[] getGridEnvelope() {
@@ -285,6 +308,9 @@ final class VariableInfo extends Variabl
      */
     @Override
     public Object read() throws IOException, DataStoreException {
+        if (reader == null) {
+            throw new DataStoreException(unknownType());
+        }
         long length = 1;
         for (final Dimension dimension : dimensions) {
             length *= dimension.length;
@@ -292,14 +318,67 @@ final class VariableInfo extends Variabl
         if (length > Integer.MAX_VALUE) {
             throw new DataStoreException(Errors.format(Errors.Keys.ExcessiveListSize_2, name,
length));
         }
-        input.seek(offset);
-        switch (datatype) {
-            case BYTE:   return input.readBytes  ((int) length);
-            case SHORT:  return input.readShorts ((int) length);
-            case INT:    return input.readInts   ((int) length);
-            case FLOAT:  return input.readFloats ((int) length);
-            case DOUBLE: return input.readDoubles((int) length);
-            default: throw new DataStoreException(Errors.format(Errors.Keys.UnknownType_1,
datatype));
+        final int dimension = dimensions.length;
+        final long[] size  = new long[dimension];
+        final int [] sub   = new int [dimension];
+        for (int i=0; i<dimension; i++) {
+            sub [i] = 1;
+            size[i] = dimensions[(dimension - 1) - i].length();
+        }
+        return reader.read(new Region(size, new long[dimension], size, sub));
+    }
+
+    /**
+     * Reads a sub-sampled sub-area of the variable.
+     *
+     * @param  areaLower   Index of the first value to read along each dimension, as unsigned
integers.
+     * @param  areaUpper   Index after the last value to read along each dimension, as unsigned
integers.
+     * @param  subsampling Sub-sampling along each dimension. 1 means no sub-sampling.
+     * @return The data as an array of a Java primitive type.
+     */
+    @Override
+    public Object read(int[] areaLower, int[] areaUpper, int[] subsampling) throws IOException,
DataStoreException {
+        if (reader == null) {
+            throw new DataStoreException(unknownType());
         }
+        /*
+         * NetCDF sorts datas in reverse dimension order. Example:
+         *
+         * DIMENSIONS:
+         *   time: 3
+         *   lat : 2
+         *   lon : 4
+         *
+         * VARIABLES:
+         *   temperature (time,lat,lon)
+         *
+         * DATA INDICES:
+         *   (0,0,0) (0,0,1) (0,0,2) (0,0,3)
+         *   (0,1,0) (0,1,1) (0,1,2) (0,1,3)
+         *   (1,0,0) (1,0,1) (1,0,2) (1,0,3)
+         *   (1,1,0) (1,1,1) (1,1,2) (1,1,3)
+         *   (2,0,0) (2,0,1) (2,0,2) (2,0,3)
+         *   (2,1,0) (2,1,1) (2,1,2) (2,1,3)
+         */
+        final int dimension = dimensions.length;
+        final long[] size  = new long[dimension];
+        final long[] lower = new long[dimension];
+        final long[] upper = new long[dimension];
+        final int [] sub   = new int [dimension];
+        for (int i=0; i<dimension; i++) {
+            final int j = (dimension - 1) - i;
+            lower[i] = Integer.toUnsignedLong(areaLower[j]);
+            upper[i] = Integer.toUnsignedLong(areaUpper[j]);
+            sub  [i] = subsampling[j];
+            size [i] = dimensions[j].length();
+        }
+        return reader.read(new Region(size, lower, upper, sub));
+    }
+
+    /**
+     * Returns the error message for an unknown data type.
+     */
+    private String unknownType() {
+        return Errors.format(Errors.Keys.UnknownType_1, "NetCDF:" + dataType);
     }
 }

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=1733845&r1=1733844&r2=1733845&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] Sun Mar  6 22:01:07 2016
@@ -19,18 +19,22 @@ package org.apache.sis.internal.netcdf.u
 import java.util.List;
 import java.io.IOException;
 import ucar.ma2.Array;
+import ucar.ma2.Section;
+import ucar.ma2.InvalidRangeException;
 import ucar.nc2.Attribute;
 import ucar.nc2.Dimension;
 import ucar.nc2.VariableIF;
 import org.apache.sis.internal.netcdf.Variable;
+import org.apache.sis.storage.DataStoreException;
 
 
 /**
  * A {@link Variable} backed by the UCAR NetCDF library.
  *
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Johann Sorel (Geomatys)
  * @since   0.3
- * @version 0.5
+ * @version 0.7
  * @module
  */
 final class VariableWrapper extends Variable {
@@ -181,4 +185,29 @@ final class VariableWrapper extends Vari
         final Array array = variable.read();
         return array.get1DJavaArray(array.getElementType());
     }
+
+    /**
+     * Reads a sub-sampled sub-area of the variable.
+     *
+     * @param  areaLower   Index of the first value to read along each dimension.
+     * @param  areaUpper   Index after the last value to read along each dimension.
+     * @param  subsampling Sub-sampling along each dimension. 1 means no sub-sampling.
+     * @return The data as an array of a Java primitive type.
+     */
+    @Override
+    public Object read(final int[] areaLower, final int[] areaUpper, final int[] subsampling)
+            throws IOException, DataStoreException
+    {
+        final int[] size = new int[areaUpper.length];
+        for (int i=0; i<size.length; i++) {
+            size[i] = areaUpper[i] - areaLower[i];
+        }
+        final Array array;
+        try {
+            array = variable.read(new Section(areaLower, size, subsampling));
+        } catch (InvalidRangeException e) {
+            throw new DataStoreException(e);
+        }
+        return array.get1DJavaArray(array.getElementType());
+    }
 }

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/DecoderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/DecoderTest.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/DecoderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/DecoderTest.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -18,6 +18,7 @@ package org.apache.sis.internal.netcdf;
 
 import java.util.Date;
 import java.io.IOException;
+import org.apache.sis.storage.DataStoreException;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -40,10 +41,11 @@ public strictfp class DecoderTest extend
     /**
      * Tests {@link Decoder#stringValue(String)} with global attributes.
      *
-     * @throws IOException If an error occurred while reading the NetCDF file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testStringValue() throws IOException {
+    public void testStringValue() throws IOException, DataStoreException {
         selectDataset(NCEP);
         assertAttributeEquals("Sea Surface Temperature Analysis Model",      TITLE);
         assertAttributeEquals("NCEP SST Global 5.0 x 2.5 degree model data", SUMMARY);
@@ -63,10 +65,11 @@ public strictfp class DecoderTest extend
     /**
      * Tests {@link Decoder#numericValue(String)} with global attributes.
      *
-     * @throws IOException If an error occurred while reading the NetCDF file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testNumericValue() throws IOException {
+    public void testNumericValue() throws IOException, DataStoreException {
         selectDataset(NCEP);
         assertAttributeEquals(Double.valueOf( -90), LATITUDE .MINIMUM);
         assertAttributeEquals(Double.valueOf( +90), LATITUDE .MAXIMUM);
@@ -80,10 +83,11 @@ public strictfp class DecoderTest extend
     /**
      * Tests {@link Decoder#dateValue(String)} with global attributes.
      *
-     * @throws IOException If an error occurred while reading the NetCDF file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testDateValue() throws IOException {
+    public void testDateValue() throws IOException, DataStoreException {
         selectDataset(NCEP);
         assertAttributeEquals(date("2005-09-22 00:00:00"), DATE_CREATED);
         assertAttributeEquals((Date) null,                 DATE_MODIFIED);
@@ -92,10 +96,11 @@ public strictfp class DecoderTest extend
     /**
      * Tests {@link Decoder#numberToDate(String, Number[])}.
      *
-     * @throws IOException If an error occurred while reading the NetCDF file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testNumberToDate() throws IOException {
+    public void testNumberToDate() throws IOException, DataStoreException {
         final Decoder decoder = selectDataset(NCEP);
         assertArrayEquals(new Date[] {
             date("2005-09-22 00:00:00")

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -17,6 +17,7 @@
 package org.apache.sis.internal.netcdf;
 
 import java.io.IOException;
+import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.netcdf.AttributeNames;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.DependsOnMethod;
@@ -55,10 +56,11 @@ public strictfp class GridGeometryTest e
     /**
      * Tests {@link GridGeometry#getSourceDimensions()} and {@link GridGeometry#getTargetDimensions()}.
      *
-     * @throws IOException If an error occurred while reading the NetCDF file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testDimensions() throws IOException {
+    public void testDimensions() throws IOException, DataStoreException {
         final GridGeometry geometry = getSingleton(filter(selectDataset(NCEP).getGridGeometries()));
         assertEquals("getSourceDimensions()", 3, geometry.getSourceDimensions());
         assertEquals("getTargetDimensions()", 3, geometry.getTargetDimensions());
@@ -67,11 +69,12 @@ public strictfp class GridGeometryTest e
     /**
      * Tests {@link GridGeometry#getAxes()}.
      *
-     * @throws IOException If an error occurred while reading the NetCDF file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
     @DependsOnMethod("testDimensions")
-    public void testAxes() throws IOException {
+    public void testAxes() throws IOException, DataStoreException {
         final Axis[] axes = getSingleton(filter(selectDataset(NCEP).getGridGeometries())).getAxes();
         assertEquals(3, axes.length);
         final Axis x = axes[2];

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.io.IOException;
 import java.lang.reflect.UndeclaredThrowableException;
+import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.logging.EmptyWarningListeners;
 import org.apache.sis.internal.netcdf.ucar.DecoderWrapper;
 import org.apache.sis.internal.system.Modules;
@@ -102,9 +103,10 @@ public abstract strictfp class TestCase
      *
      * @param  name The file name as one of the above-cited constants.
      * @return The decoder for the given name.
-     * @throws IOException If an error occurred while opening the file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
-    protected Decoder createDecoder(final String name) throws IOException {
+    protected Decoder createDecoder(final String name) throws IOException, DataStoreException
{
         return new DecoderWrapper(LISTENERS, new NetcdfDataset(open(name)));
     }
 
@@ -118,9 +120,10 @@ public abstract strictfp class TestCase
      *
      * @param  name The file name as one of the constants enumerated in the {@link #createDecoder(String)}
method.
      * @return The decoder for the given name.
-     * @throws IOException If an error occurred while opening the file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
-    protected final Decoder selectDataset(final String name) throws IOException {
+    protected final Decoder selectDataset(final String name) throws IOException, DataStoreException
{
         synchronized (DECODERS) { // Paranoiac safety, but should not be used in multi-threads
environment.
             decoder = DECODERS.get(name);
             if (decoder == null) {
@@ -137,7 +140,7 @@ public abstract strictfp class TestCase
      * Invoked after all tests in a class have been executed.
      * This method closes all NetCDF files.
      *
-     * @throws IOException If an error occurred while closing a file.
+     * @throws IOException if an error occurred while closing a file.
      */
     @AfterClass
     public static void closeAllDecoders() throws IOException {
@@ -183,7 +186,7 @@ public abstract strictfp class TestCase
      *
      * @param  expected      The expected attribute value.
      * @param  attributeName The name of the attribute to test.
-     * @throws IOException   If an error occurred while reading the NetCDF file.
+     * @throws IOException   if an error occurred while reading the NetCDF file.
      */
     protected final void assertAttributeEquals(final String expected, final String attributeName)
throws IOException {
         assertEquals(attributeName, expected, decoder.stringValue(attributeName));

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -57,10 +57,11 @@ public strictfp class VariableTest exten
      *   <li>{@link Variable#isUnsigned()}</li>
      * </ul>
      *
-     * @throws IOException If an error occurred while reading the NetCDF file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testBasicProperties() throws IOException {
+    public void testBasicProperties() throws IOException, DataStoreException {
         assertBasicPropertiesEqual(new Object[] {
         // __name______________description_________________________________datatype____dim__axis?__raster?
             "reftime",        "reference time",                            double.class,
1, false, false,
@@ -122,10 +123,11 @@ public strictfp class VariableTest exten
      * Tests {@link Variable#getGridDimensionNames()} and {@link Variable#getGridEnvelope()}.
      * Current implementation tests on the {@code "SST"} variable.
      *
-     * @throws IOException If an error occurred while reading the NetCDF file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testGridDimensions() throws IOException {
+    public void testGridDimensions() throws IOException, DataStoreException {
         final Variable variable = selectDataset(NCEP).getVariables()[21];
         assertEquals("SST", variable.getName());
 
@@ -141,10 +143,11 @@ public strictfp class VariableTest exten
     /**
      * Tests {@link Variable#getAttributeValues(String, boolean)}.
      *
-     * @throws IOException If an error occurred while reading the NetCDF file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testGetAttributes() throws IOException {
+    public void testGetAttributes() throws IOException, DataStoreException {
         final Variable[] variables = selectDataset(NCEP).getVariables();
         Variable variable = variables[9];
         assertEquals("grid_number", variable.getName());

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -46,10 +46,11 @@ public final strictfp class ChannelDecod
      * Creates a new decoder for dataset of the given name.
      *
      * @return The decoder for the given name.
-     * @throws IOException If an error occurred while opening the file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Override
-    protected Decoder createDecoder(final String name) throws IOException {
+    protected Decoder createDecoder(final String name) throws IOException, DataStoreException
{
         return createChannelDecoder(name);
     }
 
@@ -66,18 +67,15 @@ public final strictfp class ChannelDecod
      *
      * @param  name The file name as one of the above-cited constants.
      * @return The decoder for the given name.
-     * @throws IOException If an error occurred while opening the file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
-    public static Decoder createChannelDecoder(final String name) throws IOException {
+    public static Decoder createChannelDecoder(final String name) throws IOException, DataStoreException
{
         final InputStream in = IOTestCase.class.getResourceAsStream(name);
         assertNotNull(name, in);
         final ChannelDataInput input = new ChannelDataInput(name,
                 Channels.newChannel(in), ByteBuffer.allocate(4096), false);
-        try {
-            return new ChannelDecoder(LISTENERS, input);
-        } catch (DataStoreException e) {
-            throw new AssertionError(e);
-        }
+        return new ChannelDecoder(LISTENERS, input);
     }
 
     /**

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -20,6 +20,7 @@ import java.io.IOException;
 import org.apache.sis.internal.netcdf.Decoder;
 import org.apache.sis.internal.netcdf.GridGeometry;
 import org.apache.sis.internal.netcdf.GridGeometryTest;
+import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.test.DependsOn;
 
@@ -40,10 +41,11 @@ public final strictfp class GridGeometry
      * Creates a new decoder for dataset of the given name.
      *
      * @return The decoder for the given name.
-     * @throws IOException If an error occurred while opening the file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Override
-    protected Decoder createDecoder(final String name) throws IOException {
+    protected Decoder createDecoder(final String name) throws IOException, DataStoreException
{
         return ChannelDecoderTest.createChannelDecoder(name);
     }
 

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -19,6 +19,7 @@ package org.apache.sis.internal.netcdf.i
 import java.io.IOException;
 import org.apache.sis.internal.netcdf.Decoder;
 import org.apache.sis.internal.netcdf.VariableTest;
+import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.test.DependsOn;
 
 
@@ -38,10 +39,11 @@ public final strictfp class VariableInfo
      * Creates a new decoder for dataset of the given name.
      *
      * @return The decoder for the given dataset.
-     * @throws IOException If an error occurred while opening the file.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Override
-    protected Decoder createDecoder(final String name) throws IOException {
+    protected Decoder createDecoder(final String name) throws IOException, DataStoreException
{
         return ChannelDecoderTest.createChannelDecoder(name);
     }
 

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -25,6 +25,7 @@ import org.apache.sis.internal.netcdf.De
 import org.apache.sis.internal.netcdf.ucar.DecoderWrapper;
 import org.apache.sis.internal.netcdf.impl.ChannelDecoderTest;
 import org.apache.sis.metadata.iso.DefaultMetadata;
+import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.test.DependsOn;
 import org.junit.Test;
 
@@ -50,10 +51,11 @@ public final strictfp class MetadataRead
      * Reads the metadata using the NetCDF decoder embedded with SIS,
      * and compares its string representation with the expected one.
      *
-     * @throws IOException Should never happen.
+     * @throws IOException if an I/O error occurred while opening the file.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testEmbedded() throws IOException {
+    public void testEmbedded() throws IOException, DataStoreException {
         final Metadata metadata;
         try (Decoder input = ChannelDecoderTest.createChannelDecoder(NCEP)) {
             metadata = new MetadataReader(input).read();

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -596,7 +596,7 @@ public class ChannelDataInput extends Ch
          * @param  length   The number of characters to read.
          * @throws IOException if an error (including EOF) occurred while reading the stream.
          */
-        final void readFully(Buffer view, int offset, int length) throws IOException {
+        void readFully(Buffer view, int offset, int length) throws IOException {
             final int dataSizeShift = dataSizeShift();
             ensureBufferContains(Math.min(length << dataSizeShift, buffer.capacity()));
             if (view == null) {
@@ -625,8 +625,30 @@ public class ChannelDataInput extends Ch
     }
 
     /**
-     * Reads characters from the enclosing stream using the given view,
-     * and stores them into the given destination array.
+     * Reads bytes from the enclosing stream and stores them into the given destination array.
This implementation
+     * actually redirects the reading process to {@link ChannelDataInput#readFully(byte[],
int, int)} because this
+     * specialization does not need a view. This implementation is useless for {@code ChannelDataInput},
but avoid
+     * the need to implement special cases in other classes like {@link HyperRectangleReader}.
+     */
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
+    final class BytesReader extends ArrayReader {
+        /** The array where to store the values. */ private byte[] dest;
+        BytesReader(final byte[] dest) {this.dest = dest;}
+
+        @Override int    dataSizeShift()        {return 0;}
+        @Override Object dataArray()            {return dest;}
+        @Override Buffer view()                 {return buffer;}
+        @Override Buffer createView()           {return buffer;}
+        @Override void   createDataArray(int n) {dest = new byte[n];}
+        @Override void   transfer(int p, int n) {buffer.get(dest, p, n);}
+        @Override void   setDest(Object array)  {dest = (byte[]) array;};
+        @Override void readFully(Buffer view, int offset, int length) throws IOException
{
+            ChannelDataInput.this.readFully(dest, offset, length);
+        }
+    };
+
+    /**
+     * Reads characters from the enclosing stream and stores them into the given destination
array.
      */
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
     final class CharsReader extends ArrayReader {
@@ -644,8 +666,7 @@ public class ChannelDataInput extends Ch
     };
 
     /**
-     * Reads short integers from the enclosing stream using the given view,
-     * and stores them into the given destination array.
+     * Reads short integers from the enclosing stream and stores them into the given destination
array.
      */
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
     final class ShortsReader extends ArrayReader {
@@ -663,8 +684,7 @@ public class ChannelDataInput extends Ch
     };
 
     /**
-     * Reads integers from the enclosing stream using the given view,
-     * and stores them into the given destination array.
+     * Reads integers from the enclosing stream and stores them into the given destination
array.
      */
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
     final class IntsReader extends ArrayReader {
@@ -682,8 +702,7 @@ public class ChannelDataInput extends Ch
     };
 
     /**
-     * Reads long integers from the enclosing stream using the given view,
-     * and stores them into the given destination array.
+     * Reads long integers from the enclosing stream and stores them into the given destination
array.
      */
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
     final class LongsReader extends ArrayReader {
@@ -701,8 +720,7 @@ public class ChannelDataInput extends Ch
     };
 
     /**
-     * Reads float values from the enclosing stream using the given view,
-     * and stores them into the given destination array.
+     * Reads float values from the enclosing stream and stores them into the given destination
array.
      */
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
     final class FloatsReader extends ArrayReader {
@@ -720,8 +738,7 @@ public class ChannelDataInput extends Ch
     };
 
     /**
-     * Reads double values from the enclosing stream using the given view,
-     * and stores them into the given destination array.
+     * Reads double values from the enclosing stream and stores them into the given destination
array.
      */
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
     final class DoublesReader extends ArrayReader {

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=1733845&r1=1733844&r2=1733845&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] Sun Mar  6 22:01:07 2016
@@ -57,6 +57,7 @@ public final class HyperRectangleReader
             throws DataStoreException
     {
         switch (dataType) {
+            case Numbers.BYTE:      reader = input.new BytesReader  (null); break;
             case Numbers.CHARACTER: reader = input.new CharsReader  (null); break;
             case Numbers.SHORT:     reader = input.new ShortsReader (null); break;
             case Numbers.INTEGER:   reader = input.new IntsReader   (null); break;

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java?rev=1733845&r1=1733844&r2=1733845&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java
[UTF-8] Sun Mar  6 22:01:07 2016
@@ -39,6 +39,7 @@ import javax.sql.DataSource;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.ObjectConverters;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.storage.IOUtilities;
 import org.apache.sis.internal.storage.ChannelDataInput;
@@ -673,7 +674,7 @@ public class StorageConnector implements
             }
             return null;
         }
-        throw new IllegalArgumentException(Errors.format(Errors.Keys.UnknownType_1, type));
+        return ObjectConverters.convert(storage, type);
     }
 
     /**




Mime
View raw message