You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2016/10/10 15:24:06 UTC
svn commit: r1764119 [11/11] - in /sis/trunk: ./ core/
core/sis-feature/src/main/java/org/apache/sis/feature/
core/sis-feature/src/main/java/org/apache/sis/feature/builder/
core/sis-feature/src/main/java/org/apache/sis/internal/feature/
core/sis-metada...
Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -77,7 +77,7 @@ public abstract strictfp class TestCase
* supplemental formats tested in this suite. Subclasses working only with the NetCDF
* classic or 64-bits format can unconditionally returns {@code false}.
*
- * @param format Either {@code "THREDDS"} or {@code "HDF5"}.
+ * @param format either {@code "THREDDS"} or {@code "HDF5"}.
* @return {@code true} if the given supplemental format is supported.
*/
protected boolean isSupplementalFormatSupported(final String format) {
@@ -100,8 +100,8 @@ public abstract strictfp class TestCase
* reference implementation. However subclasses can override if they want to test a different
* library.
*
- * @param name The file name as one of the above-cited constants.
- * @return The decoder for the given name.
+ * @param name the file name as one of the above-cited constants.
+ * @return the decoder for the given name.
* @throws IOException if an I/O error occurred while opening the file.
* @throws DataStoreException if a logical error occurred.
*/
@@ -117,13 +117,13 @@ public abstract strictfp class TestCase
* <p>The {@linkplain Decoder#setSearchPath(String[]) search path} of the returned decoder
* is initialized to the global attributes only.</p>
*
- * @param name The file name as one of the constants enumerated in the {@link #createDecoder(String)} method.
- * @return The decoder for the given name.
+ * @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 I/O error occurred while opening the file.
* @throws DataStoreException if a logical error occurred.
*/
protected final Decoder selectDataset(final String name) throws IOException, DataStoreException {
- synchronized (DECODERS) { // Paranoiac safety, but should not be used in multi-threads environment.
+ synchronized (DECODERS) { // Paranoiac safety, but should not be used in multi-threads environment.
decoder = DECODERS.get(name);
if (decoder == null) {
decoder = createDecoder(name);
@@ -131,7 +131,7 @@ public abstract strictfp class TestCase
assertNull(DECODERS.put(name, decoder));
}
decoder.setSearchPath(GLOBAL);
- return decoder; // Reminder: Decoder instances are not thread-safe.
+ return decoder; // Reminder: Decoder instances are not thread-safe.
}
}
@@ -144,7 +144,7 @@ public abstract strictfp class TestCase
@AfterClass
public static void closeAllDecoders() throws IOException {
Throwable failure = null;
- synchronized (DECODERS) { // Paranoiac safety.
+ synchronized (DECODERS) { // Paranoiac safety.
final Iterator<Decoder> it = DECODERS.values().iterator();
while (it.hasNext()) {
final Decoder decoder = it.next();
@@ -183,9 +183,9 @@ public abstract strictfp class TestCase
* Asserts that the textual value of the named attribute is equals to the expected value.
* The {@link #selectDataset(String)} method must be invoked at least once before this method.
*
- * @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.
+ * @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.
*/
protected final void assertAttributeEquals(final String expected, final String attributeName) throws IOException {
assertEquals(attributeName, expected, decoder.stringValue(attributeName));
@@ -195,9 +195,9 @@ public abstract strictfp class TestCase
* Asserts that the numeric value of the named attribute is equals to the expected value.
* The {@link #selectDataset(String)} method must be invoked at least once before this method.
*
- * @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.
+ * @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.
*/
protected final void assertAttributeEquals(final Number expected, final String attributeName) throws IOException {
assertEquals(attributeName, expected, decoder.numericValue(attributeName));
@@ -207,9 +207,9 @@ public abstract strictfp class TestCase
* Asserts that the temporal value of the named attribute is equals to the expected value.
* The {@link #selectDataset(String)} method must be invoked at least once before this method.
*
- * @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.
+ * @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.
*/
protected final void assertAttributeEquals(final Date expected, final String attributeName) throws IOException {
assertEquals(attributeName, expected, decoder.dateValue(attributeName));
Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/VariableTest.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -17,6 +17,7 @@
package org.apache.sis.internal.netcdf;
import java.io.IOException;
+import org.apache.sis.math.Vector;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.test.DependsOn;
import org.junit.Test;
@@ -32,7 +33,7 @@ import static org.opengis.test.Assert.*;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.3
+ * @version 0.8
* @module
*/
@DependsOn(DecoderTest.class)
@@ -54,7 +55,6 @@ public strictfp class VariableTest exten
* <li>{@link Variable#getGridEnvelope()} length</li>
* <li>{@link Variable#isCoordinateSystemAxis()}</li>
* <li>{@link Variable#isCoverage(int)}</li>
- * <li>{@link Variable#isUnsigned()}</li>
* </ul>
*
* @throws IOException if an I/O error occurred while opening the file.
@@ -63,56 +63,55 @@ public strictfp class VariableTest exten
@Test
public void testBasicProperties() throws IOException, DataStoreException {
assertBasicPropertiesEqual(new Object[] {
- // __name______________description_________________________________datatype____dim__axis?__raster?
- "reftime", "reference time", double.class, 1, false, false,
- "datetime", "reference date and time", char .class, 2, false, false,
- "forecasttime", "forecast date and time", char .class, 2, false, false,
- "model_id", "generating process ID number", int .class, 1, false, false,
- "nav_model", "navigation model name", char .class, 2, false, false,
- "grid_type_code", "GRIB-1 GDS data representation type", int .class, 1, false, false,
- "grid_type", "GRIB-1 grid type", char .class, 2, false, false,
- "grid_name", "grid name", char .class, 2, false, false,
- "grid_center", "GRIB-1 originating center ID", int .class, 1, false, false,
- "grid_number", "GRIB-1 catalogued grid numbers", int .class, 2, false, false,
- "i_dim", "longitude dimension name", char .class, 2, false, false,
- "j_dim", "latitude dimension name", char .class, 2, false, false,
- "Ni", "number of points along a latitude circle", int .class, 1, false, false,
- "Nj", "number of points along a longitude circle", int .class, 1, false, false,
- "La1", "latitude of first grid point", float .class, 1, false, false,
- "Lo1", "longitude of first grid point", float .class, 1, false, false,
- "La2", "latitude of last grid point", float .class, 1, false, false,
- "Lo2", "longitude of last grid point", float .class, 1, false, false,
- "Di", "longitudinal direction increment", float .class, 1, false, false,
- "Dj", "latitudinal direction increment", float .class, 1, false, false,
- "ResCompFlag", "resolution and component flags", byte .class, 1, false, false,
- "SST", "Sea temperature", float .class, 3, false, true,
- "valtime", "valid time", double.class, 1, true, false,
- "valtime_offset", "hours from reference time", double.class, 1, true, false,
- "lat", "latitude", float .class, 1, true, false,
- "lon", "longitude", float .class, 1, true, false
+ // __name______________description_________________________________datatype_______dim__axis?__raster?
+ "reftime", "reference time", DataType.DOUBLE, 1, false, false,
+ "datetime", "reference date and time", DataType.CHAR, 2, false, false,
+ "forecasttime", "forecast date and time", DataType.CHAR, 2, false, false,
+ "model_id", "generating process ID number", DataType.INT, 1, false, false,
+ "nav_model", "navigation model name", DataType.CHAR, 2, false, false,
+ "grid_type_code", "GRIB-1 GDS data representation type", DataType.INT, 1, false, false,
+ "grid_type", "GRIB-1 grid type", DataType.CHAR, 2, false, false,
+ "grid_name", "grid name", DataType.CHAR, 2, false, false,
+ "grid_center", "GRIB-1 originating center ID", DataType.INT, 1, false, false,
+ "grid_number", "GRIB-1 catalogued grid numbers", DataType.INT, 2, false, false,
+ "i_dim", "longitude dimension name", DataType.CHAR, 2, false, false,
+ "j_dim", "latitude dimension name", DataType.CHAR, 2, false, false,
+ "Ni", "number of points along a latitude circle", DataType.INT, 1, false, false,
+ "Nj", "number of points along a longitude circle", DataType.INT, 1, false, false,
+ "La1", "latitude of first grid point", DataType.FLOAT, 1, false, false,
+ "Lo1", "longitude of first grid point", DataType.FLOAT, 1, false, false,
+ "La2", "latitude of last grid point", DataType.FLOAT, 1, false, false,
+ "Lo2", "longitude of last grid point", DataType.FLOAT, 1, false, false,
+ "Di", "longitudinal direction increment", DataType.FLOAT, 1, false, false,
+ "Dj", "latitudinal direction increment", DataType.FLOAT, 1, false, false,
+ "ResCompFlag", "resolution and component flags", DataType.BYTE, 1, false, false,
+ "SST", "Sea temperature", DataType.FLOAT, 3, false, true,
+ "valtime", "valid time", DataType.DOUBLE, 1, true, false,
+ "valtime_offset", "hours from reference time", DataType.DOUBLE, 1, true, false,
+ "lat", "latitude", DataType.FLOAT, 1, true, false,
+ "lon", "longitude", DataType.FLOAT, 1, true, false
}, selectDataset(NCEP).getVariables());
}
/**
* Compares the basic properties of the given variables.
*
- * @param expected The expected property values.
- * @param variables The variable for which to test properties.
+ * @param expected the expected property values.
+ * @param variables the variable for which to test properties.
*/
private static void assertBasicPropertiesEqual(final Object[] expected, final Variable[] variables) {
int propertyIndex = 0;
for (final Variable variable : variables) {
+ final String name = variable.getName();
+ final DataType dataType = variable.getDataType();
assertFalse("Too many variables.", propertyIndex == expected.length);
- assertEquals("getName()", expected[propertyIndex++], variable.getName());
- assertEquals("getDescription()", expected[propertyIndex++], variable.getDescription());
- assertEquals("getDataType()", expected[propertyIndex++], variable.getDataType());
- assertEquals("getDimensionLengths()", expected[propertyIndex++], variable.getGridEnvelope().length);
- assertEquals("isCoordinateSystemAxis()", expected[propertyIndex++], variable.isCoordinateSystemAxis());
- assertEquals("isCoverage(2)", expected[propertyIndex++], variable.isCoverage(2));
- assertEquals(0, propertyIndex % NUM_BASIC_PROPERTY_COLUMNS); // Sanity check for VariableTest itself.
-
- // All variable in our current test dataset are unsigned.
- assertFalse("isUnsigned()", variable.isUnsigned());
+ assertEquals(name, expected[propertyIndex++], name);
+ assertEquals(name, expected[propertyIndex++], variable.getDescription());
+ assertEquals(name, expected[propertyIndex++], dataType);
+ assertEquals(name, expected[propertyIndex++], variable.getGridEnvelope().length);
+ assertEquals(name, expected[propertyIndex++], variable.isCoordinateSystemAxis());
+ assertEquals(name, expected[propertyIndex++], variable.isCoverage(2));
+ assertEquals(0, propertyIndex % NUM_BASIC_PROPERTY_COLUMNS); // Sanity check for VariableTest itself.
}
assertEquals("Expected more variables.",
expected.length / NUM_BASIC_PROPERTY_COLUMNS,
@@ -165,19 +164,19 @@ public strictfp class VariableTest exten
/**
* Tests {@link Variable#read()} on a one-dimensional variable.
*
- * @throws IOException If an error occurred while reading the NetCDF file.
- * @throws DataStoreException Should never happen.
+ * @throws IOException if an error occurred while reading the NetCDF file.
+ * @throws DataStoreException if a logical error occurred.
*/
@Test
public void testRead1D() throws IOException, DataStoreException {
final Variable variable = selectDataset(NCEP).getVariables()[25];
assertEquals("lon", variable.getName());
- final Object data = variable.read();
- assertInstanceOf("lon", float[].class, data);
- final float[] array = (float[]) data;
- assertEquals(73, array.length);
- for (int i=0; i<array.length; i++) {
- assertEquals("Longitude value", -180 + 5*i, array[i], 0f);
+ final Vector data = variable.read();
+ assertEquals("lon", Float.class, data.getElementType());
+ final int length = data.size();
+ assertEquals("length", 73, length);
+ for (int i=0; i<length; i++) {
+ assertEquals("Longitude value", -180 + 5*i, data.floatValue(i), 0f);
}
}
}
Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/ChannelDecoderTest.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -45,7 +45,7 @@ public final strictfp class ChannelDecod
/**
* Creates a new decoder for dataset of the given name.
*
- * @return The decoder for the given name.
+ * @return the decoder for the given name.
* @throws IOException if an I/O error occurred while opening the file.
* @throws DataStoreException if a logical error occurred.
*/
@@ -65,8 +65,8 @@ public final strictfp class ChannelDecod
* <li>{@link #LANDSAT} for a NetCDF binary file.</li>
* </ul>
*
- * @param name The file name as one of the above-cited constants.
- * @return The decoder for the given name.
+ * @param name the file name as one of the above-cited constants.
+ * @return the decoder for the given name.
* @throws IOException if an I/O error occurred while opening the file.
* @throws DataStoreException if a logical error occurred.
*/
Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -40,7 +40,7 @@ public final strictfp class GridGeometry
/**
* Creates a new decoder for dataset of the given name.
*
- * @return The decoder for the given name.
+ * @return the decoder for the given name.
* @throws IOException if an I/O error occurred while opening the file.
* @throws DataStoreException if a logical error occurred.
*/
@@ -64,7 +64,7 @@ public final strictfp class GridGeometry
* Filters out the one-dimensional coordinate systems created by {@code GridGeometry}
* but not by the UCAR library.
*
- * @return The filtered grid geometries to test.
+ * @return the filtered grid geometries to test.
*/
@Override
protected GridGeometry[] filter(final GridGeometry[] geometries) {
Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/VariableInfoTest.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -21,6 +21,9 @@ import org.apache.sis.internal.netcdf.De
import org.apache.sis.internal.netcdf.VariableTest;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.test.DependsOn;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
/**
@@ -30,7 +33,7 @@ import org.apache.sis.test.DependsOn;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.3
+ * @version 0.8
* @module
*/
@DependsOn({ChannelDecoderTest.class, VariableTest.class})
@@ -38,7 +41,7 @@ public final strictfp class VariableInfo
/**
* Creates a new decoder for dataset of the given name.
*
- * @return The decoder for the given dataset.
+ * @return the decoder for the given dataset.
* @throws IOException if an I/O error occurred while opening the file.
* @throws DataStoreException if a logical error occurred.
*/
@@ -57,4 +60,14 @@ public final strictfp class VariableInfo
protected boolean isSupplementalFormatSupported(final String format) {
return false;
}
+
+ /**
+ * Tests the {@link VariableInfo#numberValues(Object)} and {@link VariableInfo#stringValues(Object)} methods.
+ */
+ @Test
+ public void testNumberValues() {
+ final float[] a = new float[] {10, 20, 1};
+ assertArrayEquals("numberValues", new Number[] { 10f, 20f, 1f }, VariableInfo.numberValues(a));
+ assertArrayEquals("stringValues", new String[] {"10.0", "20.0", "1.0"}, VariableInfo.stringValues(a));
+ }
}
Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -67,7 +67,7 @@ public final strictfp class MetadataRead
* Reads the metadata using the UCAR library and compares
* its string representation with the expected one.
*
- * @throws IOException Should never happen.
+ * @throws IOException if an I/O error occurred.
*/
@Test
public void testUCAR() throws IOException {
Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreProviderTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreProviderTest.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreProviderTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreProviderTest.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -50,7 +50,7 @@ public final strictfp class NetcdfStoreP
* Tests {@link NetcdfStoreProvider#probeContent(StorageConnector)} for an input stream which shall
* be recognized as a classic NetCDF file.
*
- * @throws DataStoreException Should never happen.
+ * @throws DataStoreException if a logical error occurred.
*/
@Test
public void testProbeContentFromStream() throws DataStoreException {
@@ -66,48 +66,48 @@ public final strictfp class NetcdfStoreP
/**
* Tests {@link NetcdfStoreProvider#probeContent(StorageConnector)} for a UCAR {@link NetcdfFile} object.
*
- * @throws IOException If an error occurred while opening the NetCDF file.
- * @throws DataStoreException Should never happen.
+ * @throws IOException if an error occurred while opening the NetCDF file.
+ * @throws DataStoreException if a logical error occurred.
*/
@Test
public void testProbeContentFromUCAR() throws IOException, DataStoreException {
- final NetcdfFile file = open(NCEP);
- final StorageConnector c = new StorageConnector(file);
- final NetcdfStoreProvider provider = new NetcdfStoreProvider();
- final ProbeResult probe = provider.probeContent(c);
- assertTrue ("isSupported", probe.isSupported());
- assertEquals("getMimeType", NetcdfStoreProvider.MIME_TYPE, probe.getMimeType());
- assertNull ("getVersion", probe.getVersion());
- file.close();
+ try (NetcdfFile file = open(NCEP)) {
+ final StorageConnector c = new StorageConnector(file);
+ final NetcdfStoreProvider provider = new NetcdfStoreProvider();
+ final ProbeResult probe = provider.probeContent(c);
+ assertTrue ("isSupported", probe.isSupported());
+ assertEquals("getMimeType", NetcdfStoreProvider.MIME_TYPE, probe.getMimeType());
+ assertNull ("getVersion", probe.getVersion());
+ }
}
/**
* Tests {@link NetcdfStoreProvider#decoder(WarningListeners, StorageConnector)} for an input stream which
* shall be recognized as a classic NetCDF file. The provider shall instantiate a {@link ChannelDecoder}.
*
- * @throws IOException If an error occurred while opening the NetCDF file.
- * @throws DataStoreException Should never happen.
+ * @throws IOException if an error occurred while opening the NetCDF file.
+ * @throws DataStoreException if a logical error occurred.
*/
@Test
public void testDecoderFromStream() throws IOException, DataStoreException {
final StorageConnector c = new StorageConnector(IOTestCase.getResourceAsStream(NCEP));
- final Decoder decoder = NetcdfStoreProvider.decoder(TestCase.LISTENERS, c);
- assertInstanceOf(NCEP, ChannelDecoder.class, decoder);
- decoder.close();
+ try (Decoder decoder = NetcdfStoreProvider.decoder(TestCase.LISTENERS, c)) {
+ assertInstanceOf(NCEP, ChannelDecoder.class, decoder);
+ }
}
/**
* Tests {@link NetcdfStoreProvider#decoder(WarningListeners, StorageConnector)} for a UCAR
* {@link NetcdfFile} object. The provider shall instantiate a {@link DecoderWrapper}.
*
- * @throws IOException If an error occurred while opening the NetCDF file.
- * @throws DataStoreException Should never happen.
+ * @throws IOException if an error occurred while opening the NetCDF file.
+ * @throws DataStoreException if a logical error occurred.
*/
@Test
public void testDecoderFromUCAR() throws IOException, DataStoreException {
final StorageConnector c = new StorageConnector(open(NCEP));
- final Decoder decoder = NetcdfStoreProvider.decoder(TestCase.LISTENERS, c);
- assertInstanceOf(NCEP, DecoderWrapper.class, decoder);
- decoder.close();
+ try (Decoder decoder = NetcdfStoreProvider.decoder(TestCase.LISTENERS, c)) {
+ assertInstanceOf(NCEP, DecoderWrapper.class, decoder);
+ }
}
}
Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreTest.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/NetcdfStoreTest.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -31,7 +31,7 @@ import static org.opengis.test.Assert.*;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.3
+ * @version 0.8
* @module
*/
@DependsOn({
@@ -42,8 +42,8 @@ public final strictfp class NetcdfStoreT
/**
* Returns a new NetCDF store to test.
*
- * @param dataset The name of the datastore to load.
- * @throws DataStoreException If an error occurred while reading the NetCDF file.
+ * @param dataset the name of the datastore to load.
+ * @throws DataStoreException if an error occurred while reading the NetCDF file.
*/
private static NetcdfStore create(final String dataset) throws DataStoreException {
return new NetcdfStore(new StorageConnector(IOTestCase.getResource(dataset)));
@@ -52,14 +52,15 @@ public final strictfp class NetcdfStoreT
/**
* Tests {@link NetcdfStore#getMetadata()}.
*
- * @throws DataStoreException If an error occurred while reading the NetCDF file.
+ * @throws DataStoreException if an error occurred while reading the NetCDF file.
*/
@Test
public void testGetMetadata() throws DataStoreException {
- final NetcdfStore store = create(NCEP);
- final Metadata metadata = store.getMetadata();
- assertSame("Should be cached.", metadata, store.getMetadata());
- store.close();
+ final Metadata metadata;
+ try (NetcdfStore store = create(NCEP)) {
+ metadata = store.getMetadata();
+ assertSame("Should be cached.", metadata, store.getMetadata());
+ }
MetadataReaderTest.compareToExpected(metadata);
}
}
Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -28,14 +28,14 @@ import org.junit.BeforeClass;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.3
+ * @version 0.8
* @module
*/
@Suite.SuiteClasses({
+ org.apache.sis.internal.netcdf.DataTypeTest.class,
org.apache.sis.internal.netcdf.DecoderTest.class,
org.apache.sis.internal.netcdf.VariableTest.class,
org.apache.sis.internal.netcdf.GridGeometryTest.class,
- org.apache.sis.internal.netcdf.impl.AttributeTest.class,
org.apache.sis.internal.netcdf.impl.ChannelDecoderTest.class,
org.apache.sis.internal.netcdf.impl.VariableInfoTest.class,
org.apache.sis.internal.netcdf.impl.GridGeometryInfoTest.class,
Modified: sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -129,7 +129,7 @@ public class MappedByteReader extends Ab
*/
@Override public int getRowNum() {
int position = getByteBuffer().position();
- int recordNumber = (position - JDK8.toUnsignedInt(this.firstRecordPosition)) / JDK8.toUnsignedInt(this.recordLength);
+ int recordNumber = (position - (firstRecordPosition & 0xFFFF)) / (recordLength & 0xFFFF);
return recordNumber;
}
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -880,7 +880,7 @@ public class ChannelDataInput extends Ch
/*
* Requested position is before the current buffer limits and we can not seek.
*/
- throw new IOException(Errors.format(Errors.Keys.StreamIsForwardOnly_1, filename));
+ throw new IOException(Resources.format(Resources.Keys.StreamIsForwardOnly_1, filename));
}
clearBitOffset();
}
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -28,7 +28,6 @@ import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.nio.ShortBuffer;
import java.nio.channels.WritableByteChannel;
-import org.apache.sis.util.resources.Errors;
import static org.apache.sis.util.ArgumentChecks.ensureBetween;
@@ -650,7 +649,7 @@ public class ChannelDataOutput extends C
}
} else {
// We can not move position beyond the buffered part.
- throw new IOException(Errors.format(Errors.Keys.StreamIsForwardOnly_1, filename));
+ throw new IOException(Resources.format(Resources.Keys.StreamIsForwardOnly_1, filename));
}
}
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageOutputStream.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageOutputStream.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageOutputStream.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageOutputStream.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -23,7 +23,6 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.WritableByteChannel;
import javax.imageio.stream.ImageOutputStream;
-import org.apache.sis.util.resources.Errors;
/**
@@ -139,7 +138,8 @@ public class ChannelImageOutputStream ex
public void writeUTF(final String s) throws IOException {
byte[] data = s.getBytes("UTF-8");
if (data.length > Short.MAX_VALUE) {
- throw new IllegalArgumentException(Errors.format(Errors.Keys.ExcessiveStringSize));
+ throw new IllegalArgumentException(Resources.format(
+ Resources.Keys.ExcessiveStringSize_3, filename, Short.MAX_VALUE, data.length));
}
final ByteOrder oldOrder = buffer.order();
buffer.order(ByteOrder.BIG_ENDIAN);
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -489,7 +489,7 @@ public final class IOUtilities extends S
if (!uri.isAbsolute()) {
// All methods invoked in this block throws IllegalArgumentException if the URI has no scheme,
// so we are better to check now and provide a more appropriate exception for this method.
- throw new IOException(Errors.format(Errors.Keys.MissingSchemeInURI));
+ throw new IOException(Resources.format(Resources.Keys.MissingSchemeInURI_1, uri));
} else try {
input = Paths.get(uri);
} catch (IllegalArgumentException | FileSystemNotFoundException e) {
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryDataTransfer.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryDataTransfer.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryDataTransfer.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryDataTransfer.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -94,7 +94,7 @@ final class MemoryDataTransfer implement
/**
* Delegates to the actual implementation.
*/
- @Override public String filename() {return filename();}
+ @Override public String filename() {return reader.filename();}
@Override public int dataSizeShift() {return reader.dataSizeShift();}
@Override public Object dataArray() {return reader.dataArray();}
@Override public Buffer view() {return reader.view();}
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -51,6 +51,7 @@ 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.setup.OptionKey;
import org.apache.sis.util.ArraysExt;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.ObjectConverter;
@@ -68,7 +69,6 @@ import org.apache.sis.internal.jdk8.Cons
import org.apache.sis.internal.jdk8.Spliterator;
import org.apache.sis.internal.jdk8.Stream;
import org.apache.sis.internal.jdk8.StreamSupport;
-import org.apache.sis.setup.OptionKey;
/**
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -27,6 +27,7 @@ import java.text.ParsePosition;
import java.text.ParseException;
import org.opengis.metadata.Metadata;
import org.opengis.referencing.ReferenceSystem;
+import org.apache.sis.internal.storage.Resources;
import org.apache.sis.io.wkt.WKTFormat;
import org.apache.sis.io.wkt.Warnings;
import org.apache.sis.storage.DataStore;
@@ -50,6 +51,13 @@ import org.apache.sis.referencing.CRS;
*/
final class Store extends DataStore {
/**
+ * Arbitrary size limit. Files that big are likely to be something else than WKT,
+ * so this limit allows earlier error reporting than loading huge amount of data
+ * before to detect that those data are not what we taught they are.
+ */
+ private static final int SIZE_LIMIT = 1000000;
+
+ /**
* The file name.
*/
private final String name;
@@ -103,8 +111,9 @@ final class Store extends DataStore {
int n;
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 DataStoreContentException(Errors.format(Errors.Keys.ExcessiveStringSize));
+ if (n >= SIZE_LIMIT) {
+ throw new DataStoreContentException(Resources.format(
+ Resources.Keys.ExcessiveStringSize_3, name, SIZE_LIMIT, n));
}
buffer = Arrays.copyOf(buffer, n << 1);
}
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -20,9 +20,9 @@ import java.util.List;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.ServiceLoader;
+import org.apache.sis.internal.storage.Resources;
import org.apache.sis.internal.system.DefaultFactories;
import org.apache.sis.util.ArgumentChecks;
-import org.apache.sis.util.resources.Errors;
/**
@@ -212,7 +212,7 @@ search: while (!deferred.isEmpty
}
}
if (open && selected == null) {
- throw new UnsupportedStorageException(Errors.format(Errors.Keys.UnknownFormatFor_1, connector.getStorageName()));
+ throw new UnsupportedStorageException(Resources.format(Resources.Keys.UnknownFormatFor_1, connector.getStorageName()));
}
return selected;
}
Modified: sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java?rev=1764119&r1=1764118&r2=1764119&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java [UTF-8] Mon Oct 10 15:24:03 2016
@@ -30,6 +30,7 @@ import org.junit.BeforeClass;
* @module
*/
@Suite.SuiteClasses({
+ org.apache.sis.internal.storage.GenericNameMapTest.class,
org.apache.sis.internal.storage.CodeTypeTest.class,
org.apache.sis.internal.storage.IOUtilitiesTest.class,
org.apache.sis.internal.storage.ChannelDataInputTest.class,