Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] Tue Mar 29 22:51:40 2016 @@ -35,8 +35,8 @@ CanNotConvertFromType_2 = Can CanNotConvertValue_2 = Can not convert value \u201c{0}\u201d to type \u2018{1}\u2019. CanNotCompute_1 = Can not compute \u201c{0}\u201d. CanNotComputeDerivative = Can not compute the derivative. -CanNotCreateObjectOfType_2 = Can not create an object of type \u201c{1}\u201d as an instance of \u2018{0}\u2019. -CanNotInstantiate_1 = Can not instantiate an object of type \u2018{0}\u2019. +CanNotCreateObjectAsInstanceOf_2 = Can not create an object \u201c{1}\u201d as an instance of class \u2018{0}\u2019. +CanNotInstantiate_1 = Can not instantiate \u201c{0}\u201d. CanNotMapAxisToDirection_2 = Can not map an axis from \u201c{0}\u201d to direction \u201c{1}\u201d. CanNotOpen_1 = Can not open \u201c{0}\u201d. CanNotParseFile_2 = Can not parse \u201c{1}\u201d as a file in the {0} format. @@ -52,6 +52,7 @@ CircularReference = Circ ClassNotFinal_1 = Class \u2018{0}\u2019 is not final. CloneNotSupported_1 = Can not clone an object of type \u2018{0}\u2019. ColinearAxisDirections_2 = Axis directions {0} and {1} are colinear. +CoordinateOperationNotFound_2 = Coordinate conversion of transformation from system \u201c{0}\u201d to \u201c{1}\u201d has not been found. DatabaseError_2 = Database error while creating a \u2018{0}\u2019 object for code \u201c{1}\u201d. DatumOriginShallBeDate = Origin of temporal datum shall be a date. DeadThread_1 = Thread \u201c{0}\u201d is dead. @@ -127,6 +128,7 @@ MismatchedDimension_3 = Argu MismatchedGridGeometry_2 = The grid geometry must be the same for \u201c{0}\u201d and \u201c{1}\u201d. MismatchedMatrixSize_4 = Mismatched matrix sizes: expected {0}\u00d7{1} but got {2}\u00d7{3}. MismatchedParameterDescriptor_1 = Mismatched descriptor for \u201c{0}\u201d parameter. +MismatchedPrimeMeridian_2 = Expected the \u201c{0}\u201d prime meridian but found \u201c{1}\u201d. MismatchedPropertyType_1 = Mismatched type for \u201c{0}\u201d property. MismatchedTransformDimension_3 = The transform has {2} {0,choice,0#source|1#target} dimension{2,choice,1#|2#s}, while {1} was expected. MismatchedValueClass_3 = Class of \u201c{0}\u201d values is \u2018{2}\u2019, but the requested type is \u2018{1}\u2019.
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] Tue Mar 29 22:51:40 2016 @@ -32,8 +32,8 @@ CanNotConvertFromType_2 = Ne p CanNotConvertValue_2 = La valeur \u00ab\u202f{0}\u202f\u00bb ne peut pas \u00eatre convertie vers le type \u2018{1}\u2019. CanNotCompute_1 = Ne peut pas calculer \u00ab\u202f{0}\u202f\u00bb. CanNotComputeDerivative = La d\u00e9riv\u00e9 ne peut pas \u00eatre calcul\u00e9e. -CanNotCreateObjectOfType_2 = Ne peut pas cr\u00e9er un objet de type \u00ab\u202f{1}\u202f\u00bb comme une instance de \u2018{0}\u2019. -CanNotInstantiate_1 = Ne peut pas cr\u00e9er un objet de type \u2018{0}\u2019. +CanNotCreateObjectAsInstanceOf_2 = Ne peut pas cr\u00e9er un objet de type \u00ab\u202f{1}\u202f\u00bb comme une instance de la classe \u2018{0}\u2019. +CanNotInstantiate_1 = Ne peut pas cr\u00e9er \u00ab\u202f{0}\u202f\u00bb. CanNotMapAxisToDirection_2 = Aucun axe de \u00ab\u202f{0}\u202f\u00bb n\u2019a pu \u00eatre associ\u00e9 \u00e0 la direction \u00ab\u202f{1}\u202f\u00bb. CanNotOpen_1 = Ne peut pas ouvrir \u00ab\u202f{0}\u202f\u00bb. CanNotParseFile_2 = Ne peut pas lire \u00ab\u202f{1}\u202f\u00bb comme un fichier au format {0}. @@ -49,6 +49,7 @@ CircularReference = R\u0 ClassNotFinal_1 = La classe \u2018{0}\u2019 n\u2019est pas finale. CloneNotSupported_1 = Un objet de type \u2018{0}\u2019 ne peut pas \u00eatre clon\u00e9. ColinearAxisDirections_2 = Les directions d\u2019axes {0} et {1} sont colin\u00e9aires. +CoordinateOperationNotFound_2 = La conversion ou transformation des coordonn\u00e9es du syst\u00e8me \u00ab\u202f{0}\u202f\u00bb vers \u00ab\u202f{1}\u202f\u00bb n\u2019a pas \u00e9t\u00e9 trouv\u00e9e. DatabaseError_2 = Erreur de base de donn\u00e9es lors de la cr\u00e9ation d\u2019un objet \u2018{0}\u2019 pour le code \u00ab\u202f{1}\u202f\u00bb. DatumOriginShallBeDate = L\u2019origine d\u2019un r\u00e9f\u00e9rentiel temporel doit \u00eatre une date. DeadThread_1 = La t\u00e2che \u00ab\u202f{0}\u202f\u00bb est morte. @@ -124,6 +125,7 @@ MismatchedDimension_3 = L\u2 MismatchedGridGeometry_2 = La g\u00e9om\u00e9trie de la grille doit \u00eatre la m\u00eame pour \u00ab\u202f{0}\u202f\u00bb et \u00ab\u202f{1}\u202f\u00bb. MismatchedMatrixSize_4 = Une matrice de taille de {0}\u00d7{1} \u00e9tait attendue mais la matrice donn\u00e9e est de taille {2}\u00d7{3}. MismatchedParameterDescriptor_1 = Le descripteur du param\u00e8tre \u00ab\u202f{0}\u202f\u00bb ne correspond pas. +MismatchedPrimeMeridian_2 = Le m\u00e9ridien d\u2019origine \u00ab\u202f{0}\u202f\u00bb \u00e9tait attendu, mais \u00ab\u202f{1}\u202f\u00bb a \u00e9t\u00e9 trouv\u00e9. MismatchedPropertyType_1 = Le type de la propri\u00e9t\u00e9 \u00ab\u202f{0}\u202f\u00bb ne correspond pas. MismatchedTransformDimension_3 = La {0,choice,0#source|1#destination} de la transformation a {2} dimension{2,choice,1#|2#s}, alors qu\u2019on en attendait {1}. MismatchedValueClass_3 = Les valeurs de \u00ab\u202f{0}\u202f\u00bb sont de la classe \u2018{2}\u2019, alors que le type demand\u00e9 \u00e9tait \u2018{1}\u2019. Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java [UTF-8] Tue Mar 29 22:51:40 2016 @@ -86,6 +86,11 @@ public final class Vocabulary extends In public static final short Attributes = 4; /** + * Axis changes + */ + public static final short AxisChanges = 98; + + /** * Barometric altitude */ public static final short BarometricAltitude = 5; @@ -96,6 +101,11 @@ public final class Vocabulary extends In public static final short Cardinality = 76; /** + * Caused by {0} + */ + public static final short CausedBy_1 = 107; + + /** * Character encoding */ public static final short CharacterEncoding = 6; @@ -161,6 +171,16 @@ public final class Vocabulary extends In public static final short DataDirectory = 88; /** + * Datum + */ + public static final short Datum = 99; + + /** + * Datum shift + */ + public static final short DatumShift = 100; + + /** * Daylight time */ public static final short DaylightTime = 13; @@ -206,11 +226,31 @@ public final class Vocabulary extends In public static final short Ellipsoid = 70; /** + * Ellipsoid change + */ + public static final short EllipsoidChange = 101; + + /** * Ellipsoidal height */ public static final short EllipsoidalHeight = 18; /** + * Geocentric + */ + public static final short Geocentric = 102; + + /** + * Geocentric conversion + */ + public static final short GeocentricConversion = 103; + + /** + * Geocentric radius + */ + public static final short GeocentricRadius = 104; + + /** * Geodetic dataset */ public static final short GeodeticDataset = 95; @@ -226,6 +266,11 @@ public final class Vocabulary extends In public static final short Identifier = 20; /** + * Identity + */ + public static final short Identity = 105; + + /** * Implementation */ public static final short Implementation = 21; @@ -246,6 +291,11 @@ public final class Vocabulary extends In public static final short Invalid = 89; /** + * Inverse operation + */ + public static final short InverseOperation = 106; + + /** * Java extensions */ public static final short JavaExtensions = 23; Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties [ISO-8859-1] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties [ISO-8859-1] Tue Mar 29 22:51:40 2016 @@ -20,8 +20,10 @@ AngularDegrees = Degrees AngularMinutes = Minutes AngularSeconds = Seconds Attributes = Attributes +AxisChanges = Axis changes BarometricAltitude = Barometric altitude Cardinality = Cardinality +CausedBy_1 = Caused by {0} CharacterEncoding = Character encoding Characteristics = Characteristics Classpath = Classpath @@ -35,6 +37,8 @@ CurrentDirectory = Current direct CycleOmitted = Cycle omitted DataBase = Database DataDirectory = Data directory +Datum = Datum +DatumShift = Datum shift DaylightTime = Daylight time DefaultValue = Default value Description = Description @@ -44,14 +48,20 @@ Directory = Directory DittoMark = \u2033 DublinJulian = Dublin Julian Ellipsoid = Ellipsoid +EllipsoidChange = Ellipsoid change EllipsoidalHeight = Ellipsoidal height +Geocentric = Geocentric +GeocentricRadius = Geocentric radius +GeocentricConversion = Geocentric conversion GeodeticDataset = Geodetic dataset Height = Height Identifier = Identifier Implementation = Implementation InBetweenWords = \u2002in\u2002 +Identity = Identity Index = Index Invalid = Invalid +InverseOperation = Inverse operation JavaExtensions = Java extensions JavaHome = Java home directory Julian = Julian Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties [ISO-8859-1] (original) +++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties [ISO-8859-1] Tue Mar 29 22:51:40 2016 @@ -27,8 +27,10 @@ AngularDegrees = Degr\u00e9s AngularMinutes = Minutes AngularSeconds = Secondes Attributes = Attributs +AxisChanges = Changements d\u2019axes BarometricAltitude = Altitude barom\u00e9trique Cardinality = Cardinalit\u00e9 +CausedBy_1 = Caus\u00e9e par {0} CharacterEncoding = Encodage des caract\u00e8res Characteristics = Caract\u00e9ristiques Classpath = Chemin de classes @@ -42,6 +44,8 @@ CurrentDirectory = R\u00e9pertoir CycleOmitted = Cycle omit DataBase = Base de donn\u00e9es DataDirectory = R\u00e9pertoire des donn\u00e9es +Datum = R\u00e9f\u00e9rentiel +DatumShift = Changement de r\u00e9f\u00e9rentiel DaylightTime = Heure normale DefaultValue = Valeur par d\u00e9faut Description = Description @@ -51,14 +55,20 @@ Directory = R\u00e9pertoir DittoMark = \u2033 DublinJulian = Julien Dublin Ellipsoid = Ellipso\u00efde +EllipsoidChange = Changement d\u2019ellipso\u00efde EllipsoidalHeight = Hauteur ellipso\u00efdale +Geocentric = G\u00e9ocentrique +GeocentricRadius = Rayon g\u00e9ocentrique +GeocentricConversion = Conversion g\u00e9ocentrique GeodeticDataset = Base de donn\u00e9es g\u00e9od\u00e9sique Height = Hauteur Identifier = Identifiant Implementation = Impl\u00e9mentation InBetweenWords = \u2002dans\u2002 +Identity = Identit\u00e9 Index = Index Invalid = Invalide +InverseOperation = Op\u00e9ration inverse JavaExtensions = Extensions du Java JavaHome = R\u00e9pertoire du Java Julian = Julien Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/LoggingWatcher.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/LoggingWatcher.java?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/LoggingWatcher.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/LoggingWatcher.java [UTF-8] Tue Mar 29 22:51:40 2016 @@ -20,6 +20,7 @@ import java.util.Queue; import java.util.LinkedList; import java.util.ConcurrentModificationException; import java.util.logging.Filter; +import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.LogRecord; import java.util.logging.SimpleFormatter; @@ -127,7 +128,9 @@ public final strictfp class LoggingWatch */ @Override public final boolean isLoggable(final LogRecord record) { - messages.add(formatter.formatMessage(record)); + if (record.getLevel().intValue() >= Level.INFO.intValue()) { + messages.add(formatter.formatMessage(record)); + } return TestCase.VERBOSE; } Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8] Tue Mar 29 22:51:40 2016 @@ -19,12 +19,14 @@ package org.apache.sis.test; import java.util.logging.Logger; import java.util.logging.Handler; import java.util.logging.ConsoleHandler; +import java.util.logging.LogManager; import java.io.Console; import java.io.PrintWriter; import java.io.StringWriter; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import org.apache.sis.util.logging.Logging; +import org.apache.sis.util.logging.MonolineFormatter; import org.junit.runner.RunWith; @@ -132,6 +134,17 @@ public abstract strictfp class TestCase static final Logger LOGGER = Logger.getLogger("org.apache.sis"); /** + * Initializes {@link MonolineFormatter} if it has been specified in the {@code logging.properties} + * configuration file. + */ + static { + final LogManager manager = LogManager.getLogManager(); + if (MonolineFormatter.class.getName().equals(manager.getProperty(ConsoleHandler.class.getName() + ".formatter"))) { + MonolineFormatter.install(); + } + } + + /** * Sets the encoding of the console logging handler, if an encoding has been specified. * Note that we look specifically for {@link ConsoleHandler}; we do not generalize to * {@link StreamHandler} because the log files may not be intended for being show in Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java [UTF-8] Tue Mar 29 22:51:40 2016 @@ -161,15 +161,22 @@ public abstract strictfp class XMLTestCa /** * Returns the URL to the XML file of the given name. - * The file shall be in the same package than the final subclass of {@code this}. + * The file shall be in the same package than a subclass of {@code this}. + * This method begins the search in the package of {@link #getClass()}. + * If the resource is not found in that package, then this method searches in the parent classes. + * The intend is to allow some test classes to be overridden in different modules. * * @param filename The name of the XML file. * @return The URL to the given XML file. */ private URL getResource(final String filename) { - final URL resource = getClass().getResource(filename); - assertNotNull(filename, resource); - return resource; + Class<?> c = getClass(); + do { + final URL resource = c.getResource(filename); + if (resource != null) return resource; + c = c.getSuperclass(); + } while (!c.equals(XMLTestCase.class)); + throw new AssertionError("Test resource not found: " + filename); } /** Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/ExceptionsTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/ExceptionsTest.java?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/ExceptionsTest.java [UTF-8] (original) +++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/ExceptionsTest.java [UTF-8] Tue Mar 29 22:51:40 2016 @@ -17,6 +17,7 @@ package org.apache.sis.util; import java.util.Locale; +import java.io.IOException; import java.io.FileNotFoundException; import org.apache.sis.test.TestCase; import org.junit.Test; @@ -29,7 +30,7 @@ import static org.junit.Assert.*; * * @author Martin Desruisseaux (Geomatys) * @since 0.4 - * @version 0.4 + * @version 0.7 * @module */ public final strictfp class ExceptionsTest extends TestCase { @@ -40,7 +41,7 @@ public final strictfp class ExceptionsTe public void testFormatChainedMessages() { final String lineSeparator = System.lineSeparator(); final FileNotFoundException cause = new FileNotFoundException("MisingFile.txt"); - cause.initCause(new Exception("Disk is not mounted.")); + cause.initCause(new IOException("Disk is not mounted.")); final Exception e = new Exception("Can not find “MisingFile.txt”.", cause); /* * The actual sequence of messages (with their cause is): @@ -51,15 +52,17 @@ public final strictfp class ExceptionsTe * * But the second line shall be omitted because it duplicates the first line. */ + String message = Exceptions.formatChainedMessages(Locale.ENGLISH, null, e); assertEquals("Can not find “MisingFile.txt”." + lineSeparator + - "Disk is not mounted.", - Exceptions.formatChainedMessages(Locale.ENGLISH, null, e)); + "Caused by IOException: Disk is not mounted.", + message); /* * Test again with a header. */ + message = Exceptions.formatChainedMessages(Locale.ENGLISH, "Error while creating the data store.", e); assertEquals("Error while creating the data store." + lineSeparator + - "Can not find “MisingFile.txt”." + lineSeparator + - "Disk is not mounted.", - Exceptions.formatChainedMessages(Locale.ENGLISH, "Error while creating the data store.", e)); + "Caused by Exception: Can not find “MisingFile.txt”." + lineSeparator + + "Caused by IOException: Disk is not mounted.", + message); } } Modified: sis/branches/JDK7/src/main/config/logging.properties URL: http://svn.apache.org/viewvc/sis/branches/JDK7/src/main/config/logging.properties?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/src/main/config/logging.properties [UTF-8] (original) +++ sis/branches/JDK7/src/main/config/logging.properties [UTF-8] Tue Mar 29 22:51:40 2016 @@ -19,5 +19,14 @@ handlers= java.util.logging.ConsoleHandl # Default global logging level. .level= CONFIG -# Set the message that are printed on the console to INFO and above. -java.util.logging.ConsoleHandler.level = CONFIG +# Enable debugging information for Apache SIS packages. +org.apache.sis.level= FINE + +# Set the message that are printed on the console to FINE and above. +# FINE provides debugging information normally hidden in production. +java.util.logging.ConsoleHandler.level = FINE + +# The MonolineFormatter is specific to Apache SIS and optional. +# See its javadoc for information on configuration options. +java.util.logging.ConsoleHandler.formatter = org.apache.sis.util.logging.MonolineFormatter +org.apache.sis.util.logging.MonolineFormatter.source = class.method Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java [UTF-8] (original) +++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java [UTF-8] Tue Mar 29 22:51:40 2016 @@ -222,7 +222,7 @@ public abstract class ChannelData { final int n = (int) (position - bufferOffset); final int p = buffer.position() - n; final int r = buffer.limit() - n; - flushAndSetPosition(n); // Number of bytes to forget. + flushAndSetPosition(n); // Number of bytes to forget. buffer.compact().position(p).limit(r); /* * Discard trailing obsolete marks. Note that obsolete marks between valid marks @@ -242,7 +242,7 @@ public abstract class ChannelData { } /** - * Writes (if applicable) the buffer content up to the given position, then set the buffer position + * Writes (if applicable) the buffer content up to the given position, then sets the buffer position * to the given value. The {@linkplain ByteBuffer#limit() buffer limit} is unchanged, and the buffer * offset is incremented by the given value. */ @@ -327,6 +327,9 @@ public abstract class ChannelData { @Debug @Override public String toString() { - return getClass().getSimpleName() + "[“" + filename + "” at " + getStreamPosition() + ']'; + final StringBuilder b = new StringBuilder().append(getClass().getSimpleName()).append("[“").append(filename).append('”'); + // Even if the buffer should not be null, it is useful to keep the toString() method robust. + if (buffer != null) b.append(" at ").append(getStreamPosition()); + return b.append(']').toString(); } } Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java [UTF-8] (original) +++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java [UTF-8] Tue Mar 29 22:51:40 2016 @@ -28,6 +28,7 @@ import java.nio.FloatBuffer; import java.nio.DoubleBuffer; import java.nio.channels.ReadableByteChannel; import org.apache.sis.util.resources.Errors; +import org.apache.sis.util.Debug; import static org.apache.sis.util.ArgumentChecks.ensureBetween; @@ -519,41 +520,21 @@ public class ChannelDataInput extends Ch * Helper class for the {@code readFully(…)} methods, * in order to avoid duplicating almost identical code many times. */ - abstract class ArrayReader { + abstract class ArrayReader implements DataTransfer { /** - * Returns the size of the Java primitive type which is the element of the array. - * The size is expressed as the number of bits to shift. - */ - abstract int dataSizeShift(); - - /** - * Returns the data as a {@code char[]}, {@code short[]}, {@code int[]}, {@code long[]}, - * {@code float[]} or {@code double[]} array. This is either the array given in argument - * to the subclass constructor, or the array created by {@link #createArray(int)}. - */ - abstract Object dataArray(); - - /** - * Creates a destination array of the given length. - */ - abstract void createDataArray(int length); - - /** - * Sets the destination to the given data array, which may be {@code null}. - */ - abstract void setDest(Object array) throws ClassCastException; - - /** - * Returns the view created by the last call to {@link #createView()}, or {@code null} if none. + * For subclass constructors only. */ - abstract Buffer view(); + ArrayReader() { + } /** - * Creates a new buffer of the type required by the array to fill. - * This method is guaranteed to be invoked exactly once, after the - * {@link ChannelDataInput#buffer} contains enough data. + * Returns a file identifier for error messages or debugging purpose. */ - abstract Buffer createView(); + @Debug + @Override + public final String filename() { + return filename; + } /** * Transfers the data from the buffer created by {@link #createView()} to array @@ -563,19 +544,6 @@ public class ChannelDataInput extends Ch abstract void transfer(int offset, int n); /** - * For subclass constructors only. - */ - ArrayReader() { - } - - /** - * Returns the enclosing data input. - */ - final ChannelDataInput input() { - return ChannelDataInput.this; - } - - /** * Skips the given amount of bytes in the buffer. It is caller responsibility to ensure * that there is enough bytes remaining in the buffer. */ @@ -584,8 +552,16 @@ public class ChannelDataInput extends Ch } /** - * Reads {@code length} characters from the stream, and stores them into the array - * known to subclass, starting at index {@code offset}. + * Moves to the given position in the stream. + */ + @Override + public final void seek(long n) throws IOException { + ChannelDataInput.this.seek(n); + } + + /** + * Reads {@code length} values from the stream, and stores them into the array known to subclass, + * starting at index {@code offset}. * * <p>If a non-null {@code Buffer} is given in argument to this method, then it must be a view over * the full content of {@link ChannelDataInput#buffer} (i.e. the view element at index 0 shall be @@ -593,10 +569,11 @@ public class ChannelDataInput extends Ch * * @param view Existing buffer to use as a view over {@link ChannelDataInput#buffer}, or {@code null}. * @param offset The starting position within {@code dest} to write. - * @param length The number of characters to read. + * @param length The number of values to read. * @throws IOException if an error (including EOF) occurred while reading the stream. */ - void readFully(Buffer view, int offset, int length) throws IOException { + @Override + public void readFully(Buffer view, int offset, int length) throws IOException { final int dataSizeShift = dataSizeShift(); ensureBufferContains(Math.min(length << dataSizeShift, buffer.capacity())); if (view == null) { @@ -632,17 +609,16 @@ public class ChannelDataInput extends Ch */ @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 { + /** The array where to store the values. */ private byte[] dest; + BytesReader(final byte[] dest) {this.dest = dest;} + @Override public int dataSizeShift() {return 0;} + @Override public Object dataArray() {return dest;} + @Override public Buffer view() {return buffer;} + @Override public Buffer createView() {return buffer;} + @Override public void createDataArray(int n) {dest = new byte[n];} + @Override void transfer(int p, int n) {buffer.get(dest, p, n);} + @Override public void setDest(Object array) {dest = (byte[]) array;}; + @Override public void readFully(Buffer view, int offset, int length) throws IOException { ChannelDataInput.this.readFully(dest, offset, length); } }; @@ -652,17 +628,17 @@ public class ChannelDataInput extends Ch */ @SuppressWarnings("ReturnOfCollectionOrArrayField") final class CharsReader extends ArrayReader { - /** A view over the enclosing byte buffer. */ private CharBuffer view; - /** The array where to store the values. */ private char[] dest; - CharsReader(final char[] dest) {this.dest = dest;} - - @Override int dataSizeShift() {return 1;} - @Override Object dataArray() {return dest;} - @Override Buffer view() {return view;} - @Override Buffer createView() {return view = buffer.asCharBuffer();} - @Override void createDataArray(int n) {dest = new char[n];} - @Override void transfer(int p, int n) {view.get(dest, p, n);} - @Override void setDest(Object array) {dest = (char[]) array;}; + /** A view over the enclosing byte buffer. */ private CharBuffer view; + /** The array where to store the values. */ private char[] dest; + CharsReader(final CharBuffer source) {this.view = source;} + CharsReader(final char[] dest) {this.dest = dest;} + @Override public int dataSizeShift() {return 1;} + @Override public Object dataArray() {return dest;} + @Override public Buffer view() {return view;} + @Override public Buffer createView() {return view = buffer.asCharBuffer();} + @Override public void createDataArray(int n) {dest = new char[n];} + @Override void transfer(int p, int n) {view.get(dest, p, n);} + @Override public void setDest(Object array) {dest = (char[]) array;}; }; /** @@ -670,17 +646,17 @@ public class ChannelDataInput extends Ch */ @SuppressWarnings("ReturnOfCollectionOrArrayField") final class ShortsReader extends ArrayReader { - /** A view over the enclosing byte buffer. */ private ShortBuffer view; - /** The array where to store the values. */ private short[] dest; - ShortsReader(final short[] dest) {this.dest = dest;} - - @Override int dataSizeShift() {return 1;} - @Override Object dataArray() {return dest;} - @Override Buffer view() {return view;} - @Override Buffer createView() {return view = buffer.asShortBuffer();} - @Override void createDataArray(int n) {dest = new short[n];} - @Override void transfer(int p, int n) {view.get(dest, p, n);} - @Override void setDest(Object array) {dest = (short[]) array;}; + /** A view over the enclosing byte buffer. */ private ShortBuffer view; + /** The array where to store the values. */ private short[] dest; + ShortsReader(final ShortBuffer source) {this.view = source;} + ShortsReader(final short[] dest) {this.dest = dest;} + @Override public int dataSizeShift() {return 1;} + @Override public Object dataArray() {return dest;} + @Override public Buffer view() {return view;} + @Override public Buffer createView() {return view = buffer.asShortBuffer();} + @Override public void createDataArray(int n) {dest = new short[n];} + @Override void transfer(int p, int n) {view.get(dest, p, n);} + @Override public void setDest(Object array) {dest = (short[]) array;}; }; /** @@ -688,17 +664,17 @@ public class ChannelDataInput extends Ch */ @SuppressWarnings("ReturnOfCollectionOrArrayField") final class IntsReader extends ArrayReader { - /** A view over the enclosing byte buffer. */ private IntBuffer view; - /** The array where to store the values. */ private int[] dest; - IntsReader(final int[] dest) {this.dest = dest;} - - @Override int dataSizeShift() {return 2;} - @Override Object dataArray() {return dest;} - @Override Buffer view() {return view;} - @Override Buffer createView() {return view = buffer.asIntBuffer();} - @Override void createDataArray(int n) {dest = new int[n];} - @Override void transfer(int p, int n) {view.get(dest, p, n);} - @Override void setDest(Object array) {dest = (int[]) array;}; + /** A view over the enclosing byte buffer. */ private IntBuffer view; + /** The array where to store the values. */ private int[] dest; + IntsReader(final IntBuffer source) {this.view = source;} + IntsReader(final int[] dest) {this.dest = dest;} + @Override public int dataSizeShift() {return 2;} + @Override public Object dataArray() {return dest;} + @Override public Buffer view() {return view;} + @Override public Buffer createView() {return view = buffer.asIntBuffer();} + @Override public void createDataArray(int n) {dest = new int[n];} + @Override void transfer(int p, int n) {view.get(dest, p, n);} + @Override public void setDest(Object array) {dest = (int[]) array;}; }; /** @@ -706,17 +682,17 @@ public class ChannelDataInput extends Ch */ @SuppressWarnings("ReturnOfCollectionOrArrayField") final class LongsReader extends ArrayReader { - /** A view over the enclosing byte buffer. */ private LongBuffer view; - /** The array where to store the values. */ private long[] dest; - LongsReader(final long[] dest) {this.dest = dest;} - - @Override int dataSizeShift() {return 3;} - @Override Object dataArray() {return dest;} - @Override Buffer view() {return view;} - @Override Buffer createView() {return view = buffer.asLongBuffer();} - @Override void createDataArray(int n) {dest = new long[n];} - @Override void transfer(int p, int n) {view.get(dest, p, n);} - @Override void setDest(Object array) {dest = (long[]) array;}; + /** A view over the enclosing byte buffer. */ private LongBuffer view; + /** The array where to store the values. */ private long[] dest; + LongsReader(final LongBuffer source) {this.view = source;} + LongsReader(final long[] dest) {this.dest = dest;} + @Override public int dataSizeShift() {return 3;} + @Override public Object dataArray() {return dest;} + @Override public Buffer view() {return view;} + @Override public Buffer createView() {return view = buffer.asLongBuffer();} + @Override public void createDataArray(int n) {dest = new long[n];} + @Override void transfer(int p, int n) {view.get(dest, p, n);} + @Override public void setDest(Object array) {dest = (long[]) array;}; }; /** @@ -724,17 +700,17 @@ public class ChannelDataInput extends Ch */ @SuppressWarnings("ReturnOfCollectionOrArrayField") final class FloatsReader extends ArrayReader { - /** A view over the enclosing byte buffer. */ private FloatBuffer view; - /** The array where to store the values. */ private float[] dest; - FloatsReader(final float[] dest) {this.dest = dest;} - - @Override int dataSizeShift() {return 2;} - @Override Object dataArray() {return dest;} - @Override Buffer view() {return view;} - @Override Buffer createView() {return view = buffer.asFloatBuffer();} - @Override void createDataArray(int n) {dest = new float[n];} - @Override void transfer(int p, int n) {view.get(dest, p, n);} - @Override void setDest(Object array) {dest = (float[]) array;}; + /** A view over the enclosing byte buffer. */ private FloatBuffer view; + /** The array where to store the values. */ private float[] dest; + FloatsReader(final FloatBuffer source) {this.view = source;} + FloatsReader(final float[] dest) {this.dest = dest;} + @Override public int dataSizeShift() {return 2;} + @Override public Object dataArray() {return dest;} + @Override public Buffer view() {return view;} + @Override public Buffer createView() {return view = buffer.asFloatBuffer();} + @Override public void createDataArray(int n) {dest = new float[n];} + @Override void transfer(int p, int n) {view.get(dest, p, n);} + @Override public void setDest(Object array) {dest = (float[]) array;}; }; /** @@ -742,17 +718,17 @@ public class ChannelDataInput extends Ch */ @SuppressWarnings("ReturnOfCollectionOrArrayField") final class DoublesReader extends ArrayReader { - /** A view over the enclosing byte buffer. */ private DoubleBuffer view; - /** The array where to store the values. */ private double[] dest; - DoublesReader(final double[] dest) {this.dest = dest;} - - @Override int dataSizeShift() {return 3;} - @Override Object dataArray() {return dest;} - @Override Buffer view() {return view;} - @Override Buffer createView() {return view = buffer.asDoubleBuffer();} - @Override void createDataArray(int n) {dest = new double[n];} - @Override void transfer(int p, int n) {view.get(dest, p, n);} - @Override void setDest(Object array) {dest = (double[]) array;}; + /** A view over the enclosing byte buffer. */ private DoubleBuffer view; + /** The array where to store the values. */ private double[] dest; + DoublesReader(final DoubleBuffer source) {this.view = source;} + DoublesReader(final double[] dest) {this.dest = dest;} + @Override public int dataSizeShift() {return 3;} + @Override public Object dataArray() {return dest;} + @Override public Buffer view() {return view;} + @Override public Buffer createView() {return view = buffer.asDoubleBuffer();} + @Override public void createDataArray(int n) {dest = new double[n];} + @Override void transfer(int p, int n) {view.get(dest, p, n);} + @Override public void setDest(Object array) {dest = (double[]) array;}; }; /** Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/HyperRectangleReader.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/HyperRectangleReader.java?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/HyperRectangleReader.java [UTF-8] (original) +++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/HyperRectangleReader.java [UTF-8] Tue Mar 29 22:51:40 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.util.Debug; /** @@ -39,7 +40,7 @@ public final class HyperRectangleReader /** * The channel from which to read the values, together with a buffer for transferring data. */ - private final ChannelDataInput.ArrayReader reader; + private final DataTransfer reader; /** * The {@link #input} position of the first sample (ignoring sub-area and sub-sampling). @@ -58,13 +59,13 @@ 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; - case Numbers.LONG: reader = input.new LongsReader (null); break; - case Numbers.FLOAT: reader = input.new FloatsReader (null); break; - case Numbers.DOUBLE: reader = input.new DoublesReader(null); break; + case Numbers.BYTE: reader = input.new BytesReader ( null); break; + case Numbers.CHARACTER: reader = input.new CharsReader ((char[]) null); break; + case Numbers.SHORT: reader = input.new ShortsReader ((short[]) null); break; + case Numbers.INTEGER: reader = input.new IntsReader ((int[]) null); break; + 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)); } this.origin = origin; @@ -80,12 +81,26 @@ public final class HyperRectangleReader } /** - * Returns the data input specified at construction time. + * Creates a new reader for the data in an existing buffer. + * The data will be read from the current buffer position to the buffer limit. * - * @return The input channel together with the buffer. + * @param filename A data source name, for error messages or debugging purpose. + * @param data A buffer containing the data to read. + * @throws IOException should never happen. */ - public final ChannelDataInput input() { - return reader.input(); + public HyperRectangleReader(final String filename, final Buffer data) throws IOException { + reader = new MemoryDataTransfer(filename, data).reader(); + origin = 0; + } + + /** + * Returns a file identifier for error messages or debugging purpose. + * + * @return the file identifier. + */ + @Debug + public String filename() { + return reader.filename(); } /** @@ -109,10 +124,9 @@ public final class HyperRectangleReader } try { reader.createDataArray(region.targetLength(region.getDimension())); - final ChannelDataInput input = reader.input(); final Buffer view = reader.view(); loop: do { - input.seek(streamPosition); + reader.seek(streamPosition); assert reader.view() == view; reader.readFully(view, arrayPosition, contiguousDataLength); for (int i=0; i<cursor.length; i++) { Modified: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/HyperRectangleReaderTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/HyperRectangleReaderTest.java?rev=1737072&r1=1737071&r2=1737072&view=diff ============================================================================== --- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/HyperRectangleReaderTest.java [UTF-8] (original) +++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/HyperRectangleReaderTest.java [UTF-8] Tue Mar 29 22:51:40 2016 @@ -83,8 +83,10 @@ public final strictfp class HyperRectang * Sample values are index values encoded in base 10. For example the value at index (4,1,2,3) will be 4123. * * @param random The random number generator to use for initializing the test. + * @param useChannel {@code true} for fetching the data from channel to a small buffer, + * or {@code false} if the data are expected to be fully contained in the buffer. */ - private void initialize(final Random random) throws IOException, DataStoreException { + private void initialize(final Random random, final boolean useChannel) throws IOException, DataStoreException { /* * Compute a random hyper-rectangle size, sub-region and sub-sampling. Each dimension will have a * size between 1 to 10, so we will be able to use decimal digits from 0 to 9 in the sample values. @@ -118,7 +120,7 @@ public final strictfp class HyperRectang * Fill the array with short values using the encoding describes in javadoc. * Then wrap the array in a pseudo-channel so we can create the reader to test. */ - ShortBuffer view = ByteBuffer.wrap(array, origin, length*(Short.SIZE / Byte.SIZE)).order(ByteOrder.nativeOrder()).asShortBuffer(); + final ShortBuffer view = ByteBuffer.wrap(array, origin, length*(Short.SIZE / Byte.SIZE)).order(ByteOrder.nativeOrder()).asShortBuffer(); for (int i3=0; i3<size[3]; i3++) { for (int i2=0; i2<size[2]; i2++) { for (int i1=0; i1<size[1]; i1++) { @@ -129,10 +131,15 @@ public final strictfp class HyperRectang } } assertEquals(length, view.position()); - final ByteArrayChannel channel = new ByteArrayChannel(array, true); - final ByteBuffer buffer = ByteBuffer.allocate(random.nextInt(20) + 20).order(ByteOrder.nativeOrder()); - final ChannelDataInput input = new ChannelDataInput("HyperRectangle", channel, buffer, false); - reader = new HyperRectangleReader(Numbers.SHORT, input, origin); + if (useChannel) { + final ByteArrayChannel channel = new ByteArrayChannel(array, true); + final ByteBuffer buffer = ByteBuffer.allocate(random.nextInt(20) + 20).order(ByteOrder.nativeOrder()); + final ChannelDataInput input = new ChannelDataInput("HyperRectangle in channel", channel, buffer, false); + reader = new HyperRectangleReader(Numbers.SHORT, input, origin); + } else { + view.clear(); + reader = new HyperRectangleReader("HyperRectangle in buffer", view); + } } /** @@ -166,7 +173,7 @@ public final strictfp class HyperRectang */ @Test public void testSubRegion() throws IOException, DataStoreException { - initialize(TestUtilities.createRandomNumberGenerator()); + initialize(TestUtilities.createRandomNumberGenerator(), true); Arrays.fill(subsampling, 0, subsampling.length, 1); verifyRegionRead(); } @@ -179,7 +186,7 @@ public final strictfp class HyperRectang */ @Test public void testSubSampling() throws IOException, DataStoreException { - initialize(TestUtilities.createRandomNumberGenerator()); + initialize(TestUtilities.createRandomNumberGenerator(), true); System.arraycopy(size, 0, upper, 0, size.length); Arrays.fill(lower, 0, lower.length, 0); verifyRegionRead(); @@ -194,7 +201,20 @@ public final strictfp class HyperRectang @Test @DependsOnMethod({"testSubRegion", "testSubSampling"}) public void testRandom() throws IOException, DataStoreException { - initialize(TestUtilities.createRandomNumberGenerator()); + initialize(TestUtilities.createRandomNumberGenerator(), true); + verifyRegionRead(); + } + + /** + * Tests reading data from an existing buffer, without channel. + * + * @throws IOException should never happen. + * @throws DataStoreException should never happen. + */ + @Test + @DependsOnMethod("testRandom") + public void testMemoryTransfer() throws IOException, DataStoreException { + initialize(TestUtilities.createRandomNumberGenerator(), false); verifyRegionRead(); } }
