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 2014/04/27 22:22:59 UTC
svn commit: r1590484 - in /sis/trunk: ./ core/sis-build-helper/src/site/
core/sis-utility/src/main/java/org/apache/sis/util/resources/
core/sis-utility/src/main/javadoc/ core/sis-utility/src/site/
core/sis-utility/src/test/java/org/apache/sis/test/ src...
Author: desruisseaux
Date: Sun Apr 27 20:22:58 2014
New Revision: 1590484
URL: http://svn.apache.org/r1590484
Log:
Merge from JDK6 branch.
Added:
sis/trunk/src/README.txt
- copied unchanged from r1590483, sis/branches/JDK6/src/README.txt
sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java
- copied unchanged from r1590483, sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java
sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
- copied unchanged from r1590483, sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageOutputStream.java
- copied unchanged from r1590483, sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageOutputStream.java
sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ByteArrayChannel.java
- copied unchanged from r1590483, sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ByteArrayChannel.java
sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java
- copied unchanged from r1590483, sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataOutputTest.java
sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataTestCase.java
- copied unchanged from r1590483, sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataTestCase.java
sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageOutputStreamTest.java
- copied unchanged from r1590483, sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageOutputStreamTest.java
sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryCacheImageOutputStream.java
- copied unchanged from r1590483, sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryCacheImageOutputStream.java
Removed:
sis/trunk/core/sis-build-helper/src/site/
sis/trunk/core/sis-utility/src/site/
Modified:
sis/trunk/ (props changed)
sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
sis/trunk/core/sis-utility/src/main/javadoc/overview.html
sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java
sis/trunk/pom.xml
sis/trunk/src/main/javadoc/stylesheet.css
sis/trunk/src/site/apt/index.apt
sis/trunk/src/site/site.xml
sis/trunk/storage/sis-storage/pom.xml
sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageInputStream.java
sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java
sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java
sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
Propchange: sis/trunk/
------------------------------------------------------------------------------
Merged /sis/branches/JDK8:r1589202-1590469
Merged /sis/branches/JDK7:r1589203-1590476
Merged /sis/branches/JDK6:r1589209-1590483
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] Sun Apr 27 20:22:58 2014
@@ -215,6 +215,11 @@ public final class Errors extends Indexe
public static final short ExcessiveListSize_2 = 25;
/**
+ * The character string is too long.
+ */
+ public static final short ExcessiveStringSize = 153;
+
+ /**
* Attribute “{0}” is not allowed for an object of type ‘{1}’.
*/
public static final short ForbiddenAttribute_2 = 26;
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] Sun Apr 27 20:22:58 2014
@@ -54,6 +54,7 @@ EmptyEnvelope2D = Enve
EmptyProperty_1 = Property named \u201c{0}\u201d shall not be empty.
ExcessiveArgumentSize_3 = Argument \u2018{0}\u2019 shall not contain more than {1} elements. A number of {2} is excessive.
ExcessiveListSize_2 = A size of {1} elements is excessive for the \u201c{0}\u201d list.
+ExcessiveStringSize = The character string is too long.
ForbiddenAttribute_2 = Attribute \u201c{0}\u201d is not allowed for an object of type \u2018{1}\u2019.
IllegalArgumentClass_2 = Argument \u2018{0}\u2019 can not be an instance of \u2018{1}\u2019.
IllegalArgumentClass_3 = Argument \u2018{0}\u2019 can not be an instance of \u2018{2}\u2019. Expected an instance of \u2018{1}\u2019 or derived type.
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] Sun Apr 27 20:22:58 2014
@@ -44,6 +44,7 @@ EmptyEnvelope2D = L\u2
EmptyProperty_1 = La propri\u00e9t\u00e9 nomm\u00e9e \u00ab\u202f{0}\u202f\u00bb ne doit pas \u00eatre vide.
ExcessiveArgumentSize_3 = L\u2019argument \u2018{0}\u2019 ne peut pas contenir plus de {1} \u00e9l\u00e9ments. Un nombre de {2} est excessif.
ExcessiveListSize_2 = Une taille de {1} \u00e9l\u00e9ments est excessive pour la liste \u00ab\u202f{0}\u202f\u00bb.
+ExcessiveStringSize = La cha\u00eene de caract\u00e8res est trop longue.
ForbiddenAttribute_2 = L\u2019attribut \u00ab\u202f{0}\u202f\u00bb n\u2019est pas autoris\u00e9 pour un objet de type \u2018{1}\u2019.
IllegalArgumentClass_2 = L\u2019argument \u2018{0}\u2019 ne peut pas \u00eatre de type \u2018{1}\u2019.
IllegalArgumentClass_3 = L\u2019argument \u2018{0}\u2019 ne peut pas \u00eatre de type \u2018{2}\u2019. Une instance de \u2018{1}\u2019 ou d\u2019un type d\u00e9riv\u00e9 \u00e9tait attendue.
Modified: sis/trunk/core/sis-utility/src/main/javadoc/overview.html
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/javadoc/overview.html?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/javadoc/overview.html (original)
+++ sis/trunk/core/sis-utility/src/main/javadoc/overview.html Sun Apr 27 20:22:58 2014
@@ -28,5 +28,20 @@
Overview of Apache <code>sis-utility</code> module.
This Javadoc is only about one specific module. For the full Apache SIS project,
see the <a href="http://sis.apache.org/apidocs/overview-summary.html">aggregated Javadoc</a>.
+
+ <p>The <code>sis-utility</code> module provides simple data objects and miscellaneous utilities.
+ The services provided by this module include internationalization, operations on common Java types
+ like Arrays and character strings, logging, and more.</p>
+
+ <p>Some functionalities provided by this module may overlap some external libraries like
+ <code>common-logging</code> and <code>commons-collections</code>. However this module often implement
+ them in a slightly different way. For example instead of defining new API for logging operations,
+ SIS uses the standard Java logging framework with optional adaptors on top of <code>java.util.logging.Logger</code>
+ for users who want to redirect to other logging frameworks.</p>
+
+ <p>Since this is not the purpose of this module to compete with dedicated libraries, this
+ module should be considered as mostly internal to the Apache SIS project. For example
+ any future SIS release may change the collection implementations (how they perform
+ synchronizations, how they handle exceptions, <i>etc.</i>) in order to fit SIS needs.</p>
</body>
</html>
Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java [UTF-8] Sun Apr 27 20:22:58 2014
@@ -122,7 +122,7 @@ public strictfp class Assert extends Geo
public static void assertMultilinesEquals(final String message, final CharSequence expected, final CharSequence actual) {
final CharSequence[] expectedLines = CharSequences.splitOnEOL(expected);
final CharSequence[] actualLines = CharSequences.splitOnEOL(actual);
- final int length = Math.min(expectedLines.length, actualLines.length);
+ final int length = StrictMath.min(expectedLines.length, actualLines.length);
final StringBuilder buffer = new StringBuilder(message != null ? message : "Line").append('[');
final int base = buffer.length();
for (int i=0; i<length; i++) {
Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java [UTF-8] Sun Apr 27 20:22:58 2014
@@ -28,6 +28,7 @@ import java.text.Format;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import org.apache.sis.util.Debug;
import org.apache.sis.util.Static;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.ArgumentChecks;
@@ -44,7 +45,7 @@ import static org.junit.Assert.*;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.16)
- * @version 0.4
+ * @version 0.5
* @module
*/
public final strictfp class TestUtilities extends Static {
@@ -171,6 +172,31 @@ public final strictfp class TestUtilitie
}
/**
+ * Returns a new random number generator with the given seed. This method is used only for debugging a test failure.
+ * The seed given in argument is the value printed by the test runner. This argument shall be removed after the test
+ * has been fixed.
+ *
+ * <p>The work flow is as below:</p>
+ * <ul>
+ * <li>Uses {@link #createRandomNumberGenerator()} (without argument} in tests.</li>
+ * <li>If a test fail, find the seed value printed by the test runner, then insert that value in argument
+ * to {@code createRandomNumberGenerator(…)}.</li>
+ * <li>Debug the test.</li>
+ * <li>Once the test has been fixed, remove the argument from the {@code createRandomNumberGenerator()} call.</li>
+ * </ul>
+ *
+ * @param seed The random generator seed.
+ * @return A new random number generator initialized with the given seed.
+ *
+ * @since 0.5
+ */
+ @Debug
+ public static Random createRandomNumberGenerator(final long seed) {
+ TestCase.randomSeed = seed;
+ return new Random(seed);
+ }
+
+ /**
* Parses the date for the given string using the {@code "yyyy-MM-dd HH:mm:ss"} pattern
* in UTC timezone.
*
Modified: sis/trunk/pom.xml
URL: http://svn.apache.org/viewvc/sis/trunk/pom.xml?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/pom.xml (original)
+++ sis/trunk/pom.xml Sun Apr 27 20:22:58 2014
@@ -595,7 +595,6 @@ Apache SIS is a free software, Java lang
<additionalparam>
-link http://www.geoapi.org/snapshot/javadoc/
-link http://www.geoapi.org/snapshot/pending/
- -Xdoclint:syntax -Xdoclint:missing -Xdoclint:accessibility
</additionalparam>
<!-- Separates packages on the overview page into the groups specified. -->
Modified: sis/trunk/src/main/javadoc/stylesheet.css
URL: http://svn.apache.org/viewvc/sis/trunk/src/main/javadoc/stylesheet.css?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/src/main/javadoc/stylesheet.css (original)
+++ sis/trunk/src/main/javadoc/stylesheet.css Sun Apr 27 20:22:58 2014
@@ -149,6 +149,7 @@ div.block h6 {
/*
* Bullet and ordered lists. Put some space before and after the list.
+ * Listes of the "verbose" class also have some space betweem items.
*/
div.block ul,
div.block ol {
@@ -162,6 +163,11 @@ div.block li > ol {
margin-bottom: 6px;
}
+ul.verbose li {
+ margin-top: 6px;
+ margin-bottom: 6px;
+}
+
Modified: sis/trunk/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/sis/trunk/src/site/apt/index.apt?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/src/site/apt/index.apt [UTF-8] (original)
+++ sis/trunk/src/site/apt/index.apt [UTF-8] Sun Apr 27 20:22:58 2014
@@ -42,42 +42,5 @@ The Apache SIS™ library
SIS is a project of the {{{http://www.apache.org}Apache Software Foundation}}.
The project home is {{http://sis.apache.org}}.
-
-* Modules
-
- Maven-generated reports for SIS modules are available at the following locations:
-
- * Core
-
- * {{{./sis-build-helper/index.html}Build helper}} — Maven Mojos and Javadoc taglets for SIS build.
-
- * {{{./sis-utility/index.html}Utilities}} — simple data objects and miscellaneous utilities.
-
- * {{{./sis-metadata/index.html}Metadata}} — metadata classes derived from ISO 19115.
-
- * {{{./sis-referencing/index.html}Referencing}} — Coordinate Reference Systems (CRS), conversion and transformation services derived from ISO 19111.
-
- * {{{./sis-feature/index.html}Features}} — Representations of geographic features.
-
- * Storage
-
- * {{{./sis-storage/index.html}Storage}} — Base classes to be implemented by various storage formats.
-
- * {{{./sis-shapefile/index.html}Shapefile}} — Read and write files in the Shapefile format.
-
- * {{{./sis-netcdf/index.html}NetCDF}} — Bridge between NetCDF Climate and Forecast (CF) convention and ISO 19115 metadata.
-
- * Applications
-
- * {{{./sis-webapp/index.html}Wep application}} — Web application.
-
- * {{{./sis-console/index.html}Console application}} — Console application.
-
- * Profiles
-
- * {{{./sis-french-profile/index.html}French profile}} — Extensions to ISO-19115 metadata mandated by the French government.
-
- []
-
Apache SIS, Apache, the Apache feather logo, and the Apache SIS project logo are trademarks of
The Apache Software Foundation.
Modified: sis/trunk/src/site/site.xml
URL: http://svn.apache.org/viewvc/sis/trunk/src/site/site.xml?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/src/site/site.xml (original)
+++ sis/trunk/src/site/site.xml Sun Apr 27 20:22:58 2014
@@ -53,13 +53,9 @@
<!-- Absolute URL in order to point to the aggregated Javadoc instead than module Javadoc. -->
</menu>
- <!--
- Do not list the modules because the links generated by maven-site-plugin do not match the
- directory layout created by Jenkins (http://issues.apache.org/jira/browse/SIS-112).
- -->
-
- <menu ref="parent" inherit="top"/> <!-- Replaced by a link to the parent. -->
- <menu ref="reports" inherit="top"/> <!-- Replaced by menus for any configured reports (mailing lists, etc.) -->
+ <menu ref="parent" inherit="top"/> <!-- Replaced by a link to the parent. -->
+ <menu ref="modules" inherit="top"/> <!-- Replaced by menu for submodules. -->
+ <menu ref="reports" inherit="top"/> <!-- Replaced by menus for any configured reports (mailing lists, etc.) -->
</body>
</project>
Modified: sis/trunk/storage/sis-storage/pom.xml
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/pom.xml?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/pom.xml (original)
+++ sis/trunk/storage/sis-storage/pom.xml Sun Apr 27 20:22:58 2014
@@ -85,6 +85,16 @@ Provides the interfaces and base classes
<role>developer</role>
</roles>
</contributor>
+ <contributor>
+ <name>Rémi Maréchal</name>
+ <email>remi.marechal@geomatys.com</email>
+ <organization>Geomatys</organization>
+ <organizationUrl>http://www.geomatys.com/</organizationUrl>
+ <timezone>+1</timezone>
+ <roles>
+ <role>developer</role>
+ </roles>
+ </contributor>
</contributors>
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=1590484&r1=1590483&r2=1590484&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] Sun Apr 27 20:22:58 2014
@@ -28,7 +28,8 @@ 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;
// Related to JDK7
import java.nio.channels.FileChannel;
@@ -40,11 +41,11 @@ import java.nio.channels.FileChannel;
* before {@code ChannelDataInput} creation.
*
* {@section Encapsulation}
- * This class exposes publicly the {@linkplain #channel} and the {@linkplain #buffer} because it is not expected
- * to perform all possible data manipulations that we can do with the buffers. This class is only a helper tool,
- * which often needs to be completed by specialized operations performed directly on the buffer. However, users
- * are encouraged to transfer data from the channel to the buffer using only the methods provided in this class
- * if they want to keep the {@link #seek(long)} and {@link #getStreamPosition()} values accurate.
+ * This class exposes publicly the {@linkplain #channel} and the {@linkplain #buffer buffer} because this class
+ * is not expected to perform all possible data manipulations that we can do with the buffers. This class is only
+ * a helper tool, which often needs to be completed by specialized operations performed directly on the buffer.
+ * However, users are encouraged to transfer data from the channel to the buffer using only the methods provided
+ * in this class if they want to keep the {@link #seek(long)} and {@link #getStreamPosition()} values accurate.
*
* <p>Since this class is only a helper tool, it does not "own" the channel and consequently does not provide
* {@code close()} method. It is users responsibility to close the channel after usage.</p>
@@ -59,15 +60,10 @@ import java.nio.channels.FileChannel;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.07)
- * @version 0.4
+ * @version 0.5
* @module
*/
-public class ChannelDataInput {
- /**
- * A file identifier used only for formatting error message.
- */
- public final String filename;
-
+public class ChannelDataInput extends ChannelData {
/**
* The channel from where data are read.
* This is supplied at construction time.
@@ -75,30 +71,7 @@ public class ChannelDataInput {
public final ReadableByteChannel channel;
/**
- * The buffer to use for transferring data from the channel to memory.
- */
- public final ByteBuffer buffer;
-
- /**
- * The position of the channel when this {@code ChannelDataInput} has been created.
- * This is almost always 0, but we allow other values in case the data to read are
- * encompassed inside a bigger file.
- */
- private final long channelOffset;
-
- /**
- * The position in {@link #channel} where is located the {@link #buffer} value at index 0.
- * This is initially zero and shall be incremented as below:
- *
- * <ul>
- * <li>By {@link Buffer#position()} every time {@link ByteBuffer#compact()} is invoked.</li>
- * <li>By {@link Buffer#limit()} every time {@link ByteBuffer#clear()} is invoked.</li>
- * </ul>
- */
- private long bufferOffset;
-
- /**
- * Creates a new input source for the given channel and using the given buffer.
+ * Creates a new data input for the given channel and using the given buffer.
* If the buffer already contains some data, then the {@code filled} argument shall be {@code true}.
* Otherwise (e.g. if it is a newly created buffer), then {@code filled} shall be {@code false}.
*
@@ -112,10 +85,8 @@ public class ChannelDataInput {
public ChannelDataInput(final String filename, final ReadableByteChannel channel, final ByteBuffer buffer,
final boolean filled) throws IOException
{
- this.filename = filename;
- this.channel = channel;
- this.buffer = buffer;
- this.channelOffset = (channel instanceof FileChannel) ? ((FileChannel) channel).position() : 0;
+ super(filename, channel, buffer);
+ this.channel = channel;
if (!filled) {
buffer.clear();
channel.read(buffer);
@@ -124,32 +95,6 @@ public class ChannelDataInput {
}
/**
- * Invoked when a call to {@link ReadableByteChannel#read(ByteBuffer)} has returned zero.
- * Note that this is unrelated to end-of-file, in which case {@code read} returns -1.
- * A return value of 0 happen for example if the channel is a socket in non-blocking mode
- * and the socket buffer has not yet received new data.
- *
- * <p>The current implementation sleeps an arbitrary amount of time before to allow a new try.
- * We do that in order to avoid high CPU consumption when data are expected to take more than
- * a few nanoseconds to arrive.</p>
- *
- * @throws IOException If the implementation chooses to stop the reading process.
- */
- protected void onEmptyChannelBuffer() throws IOException {
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- /*
- * Someone doesn't want to let us sleep. Stop the reading process. We don't try to go back to work,
- * because the waiting time was short and this method is invoked in loops. Consequently if the user
- * interrupted us, it is probably because he waited for a long time and we still have not received
- * any new data.
- */
- throw new IOException(e);
- }
- }
-
- /**
* Tries to read more bytes from the channel without changing the buffer position.
* This method returns a negative number if the buffer is already full or if the channel reached the
* <cite>end of stream</cite>. Otherwise this method reads an arbitrary amount of bytes not greater
@@ -170,7 +115,7 @@ public class ChannelDataInput {
buffer.limit(capacity).position(limit);
int c = channel.read(buffer);
while (c == 0) {
- onEmptyChannelBuffer();
+ onEmptyTransfer();
c = channel.read(buffer);
}
buffer.limit(buffer.position()).position(position);
@@ -179,9 +124,9 @@ public class ChannelDataInput {
/**
* Returns {@code true} if the buffer or the channel has at least one byte remaining.
- * If the {@linkplain #buffer} has no remaining bytes, then this method will attempts
- * to read at least one byte from the {@linkplain #channel}. If no bytes can be read
- * because the channel has reached the end of stream, then this method returns {@code false}.
+ * If the {@linkplain #buffer buffer} has no remaining bytes, then this method will attempts
+ * to read at least one byte from the {@linkplain #channel}. If no bytes can be read because
+ * the channel has reached the end of stream, then this method returns {@code false}.
*
* @return {@code true} if the buffer contains at least one remaining byte.
* @throws IOException If it was necessary to read from the channel and this operation failed.
@@ -194,7 +139,7 @@ public class ChannelDataInput {
buffer.clear();
int c = channel.read(buffer);
while (c == 0) {
- onEmptyChannelBuffer();
+ onEmptyTransfer();
c = channel.read(buffer);
}
buffer.flip();
@@ -206,12 +151,12 @@ public class ChannelDataInput {
* It is caller's responsibility to ensure that the given number of bytes is
* not greater than the {@linkplain ByteBuffer#capacity() buffer capacity}.
*
- * @param n The minimal number of bytes needed in the {@linkplain #buffer}.
+ * @param n The minimal number of bytes needed in the {@linkplain #buffer buffer}.
* @throws EOFException If the channel has reached the end of stream.
* @throws IOException If an other kind of error occurred while reading.
*/
public final void ensureBufferContains(int n) throws EOFException, IOException {
- assert n <= buffer.capacity() : n;
+ assert n >= 0 && n <= buffer.capacity() : n;
n -= buffer.remaining();
if (n > 0) {
bufferOffset += buffer.position();
@@ -222,7 +167,7 @@ public class ChannelDataInput {
if (c != 0) {
throw new EOFException(eof());
}
- onEmptyChannelBuffer();
+ onEmptyTransfer();
}
n -= c;
} while (n > 0);
@@ -250,6 +195,59 @@ public class ChannelDataInput {
}
/**
+ * Pushes back the last processed byte. This is used when a call to {@code readBit()} did not
+ * used every bits in a byte, or when {@code readLine()} checked for the Windows-style of EOL.
+ */
+ final void pushBack() {
+ buffer.position(buffer.position() - 1);
+ }
+
+ /**
+ * Reads a single bit from the stream. The bit to be read depends on the
+ * {@linkplain #getBitOffset() current bit offset}.
+ *
+ * @return The value of the next bit from the stream.
+ * @throws IOException If an error occurred while reading (including EOF).
+ */
+ public final int readBit() throws IOException {
+ return (int) readBits(1);
+ }
+
+ /**
+ * Reads many bits from the stream. The first bit to be read depends on the
+ * {@linkplain #getBitOffset() current bit offset}.
+ *
+ * @param numBits The number of bits to read.
+ * @return The value of the next bits from the stream.
+ * @throws IOException If an error occurred while reading (including EOF).
+ */
+ public final long readBits(int numBits) throws IOException {
+ ensureBetween("numBits", 0, Long.SIZE, numBits);
+ if (numBits == 0) {
+ return 0;
+ }
+ /*
+ * Reads the bits available in the next bytes (all of them if bitOffset == 0)
+ * and compute the number of bits that still need to be read. That number may
+ * be negative if we have read too many bits.
+ */
+ final int bitOffset = getBitOffset();
+ long value = readByte() & (0xFF >>> bitOffset);
+ numBits -= (Byte.SIZE - bitOffset);
+ while (numBits > 0) {
+ value = (value << Byte.SIZE) | readUnsignedByte();
+ numBits -= Byte.SIZE;
+ }
+ if (numBits != 0) {
+ value >>>= (-numBits); // Discard the unwanted bits.
+ numBits += Byte.SIZE;
+ pushBack();
+ }
+ setBitOffset(numBits);
+ return value;
+ }
+
+ /**
* Reads the next byte value (8 bits) from the stream. This method ensures that there is at
* least 1 byte remaining in the buffer, reading new bytes from the channel if necessary,
* then delegates to {@link ByteBuffer#get()}.
@@ -561,7 +559,7 @@ public class ChannelDataInput {
skipInBuffer(n * dataSize);
while ((length -= n) != 0) {
offset += n;
- ensureBufferContains(dataSize);
+ ensureBufferContains(dataSize); // Actually read as much data as possible.
view.position(0).limit(buffer.remaining() / dataSize);
transfer(offset, n = Math.min(view.remaining(), length));
skipInBuffer(n * dataSize);
@@ -701,6 +699,7 @@ public class ChannelDataInput {
* @param position The position where to move.
* @throws IOException If the stream can not be moved to the given position.
*/
+ @Override
public final void seek(final long position) throws IOException {
long p = position - bufferOffset;
if (p >= 0 && p <= buffer.limit()) {
@@ -717,9 +716,7 @@ public class ChannelDataInput {
*/
((FileChannel) channel).position(channelOffset + position);
bufferOffset = position;
- buffer.clear();
- channel.read(buffer);
- buffer.flip();
+ buffer.clear().limit(0);
} else if (p >= 0) {
/*
* Requested position is after the current buffer limits and
@@ -734,7 +731,7 @@ public class ChannelDataInput {
if (c != 0) {
throw new EOFException(eof());
}
- onEmptyChannelBuffer();
+ onEmptyTransfer();
}
buffer.flip();
} while (p > buffer.limit());
@@ -746,40 +743,6 @@ public class ChannelDataInput {
*/
throw new IOException(Errors.format(Errors.Keys.StreamIsForwardOnly_1, filename));
}
- }
-
- /**
- * Sets the current byte position of the stream. This method does <strong>not</strong> seeks the stream;
- * this method only modifies the value to be returned by {@link #getStreamPosition()}. This method can
- * be invoked when some external code has performed some work with the {@linkplain #channel} and wants
- * to inform this {@code ChannelDataInput} about the new position resulting from this work.
- *
- * <p>This method does not need to be invoked when only the {@linkplain Buffer#position() buffer position}
- * has changed.</p>
- *
- * @param position The new position of the stream.
- */
- public final void setStreamPosition(final long position) {
- bufferOffset = position - buffer.position();
- }
-
- /**
- * Returns the current byte position of the stream.
- *
- * @return The position of the stream.
- */
- public final long getStreamPosition() {
- return bufferOffset + buffer.position();
- }
-
- /**
- * Returns a string representation of this object for debugging purpose.
- *
- * @return A string representation of this channel.
- */
- @Debug
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[“" + filename + "” at " + getStreamPosition() + ']';
+ clearBitOffset();
}
}
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageInputStream.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageInputStream.java?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageInputStream.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageInputStream.java [UTF-8] Sun Apr 27 20:22:58 2014
@@ -23,9 +23,6 @@ import java.nio.ByteOrder;
import java.nio.channels.ReadableByteChannel;
import javax.imageio.stream.IIOByteBuffer;
import javax.imageio.stream.ImageInputStream;
-import org.apache.sis.util.resources.Errors;
-
-import static org.apache.sis.util.ArgumentChecks.ensureBetween;
// Related to JDK7
import java.nio.channels.FileChannel;
@@ -49,7 +46,7 @@ import java.nio.channels.FileChannel;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.07)
- * @version 0.3
+ * @version 0.5
* @module
*
* @see javax.imageio.stream.FileImageInputStream
@@ -58,48 +55,7 @@ import java.nio.channels.FileChannel;
*/
public class ChannelImageInputStream extends ChannelDataInput implements ImageInputStream {
/**
- * Number of bits needed for storing the bit offset in {@link #bitPosition}.
- * The following condition must hold:
- *
- * {@preformat java
- * (1 << BIT_OFFSET_SIZE) == Byte.SIZE
- * }
- */
- private static final int BIT_OFFSET_SIZE = 3;
-
- /**
- * The current bit position within the stream. The 3 lowest bits are the bit offset,
- * and the remaining of the {@code long} value is the stream position where the bit
- * offset is valid.
- *
- * @see #getBitOffset()
- */
- private long bitPosition;
-
- /**
- * The most recent mark, or {@code null} if none.
- * This is the tail of a chained list of marks.
- */
- private Mark mark;
-
- /**
- * A mark pushed by the {@link ChannelImageInputStream#mark()} method
- * and pooled by the {@link ChannelImageInputStream#reset()} method.
- */
- private static final class Mark {
- final long position;
- final byte bitOffset;
- Mark next;
-
- Mark(long position, byte bitOffset, Mark next) {
- this.position = position;
- this.bitOffset = bitOffset;
- this.next = next;
- }
- }
-
- /**
- * Creates a new input source for the given channel and using the given buffer.
+ * Creates a new input stream for the given channel and using the given buffer.
*
* @param filename A file identifier used only for formatting error message.
* @param channel The channel from where data are read.
@@ -115,7 +71,7 @@ public class ChannelImageInputStream ext
}
/**
- * Creates a new input source from the given {@code ChannelDataInput}.
+ * Creates a new input stream from the given {@code ChannelDataInput}.
* This constructor is invoked when we need to change the implementation class
* from {@code ChannelDataInput} to {@code ChannelImageInputStream}.
*
@@ -128,7 +84,9 @@ public class ChannelImageInputStream ext
/**
* Sets the desired byte order for future reads of data values from this stream.
- * The default value is {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
+ * The default value is {@link ByteOrder#BIG_ENDIAN}.
+ *
+ * @param byteOrder The new {@linkplain #buffer buffer} byte order.
*/
@Override
public final void setByteOrder(final ByteOrder byteOrder) {
@@ -137,6 +95,9 @@ public class ChannelImageInputStream ext
/**
* Returns the byte order with which data values will be read from this stream.
+ * This is the {@linkplain #buffer buffer} byte order.
+ *
+ * @return The {@linkplain #buffer buffer} byte order.
*/
@Override
public final ByteOrder getByteOrder() {
@@ -146,6 +107,7 @@ public class ChannelImageInputStream ext
/**
* Returns the length of the stream (in bytes), or -1 if unknown.
*
+ * @return The length of the stream (in bytes), or -1 if unknown.
* @throws IOException If an error occurred while fetching the stream length.
*/
@Override
@@ -157,101 +119,6 @@ public class ChannelImageInputStream ext
}
/**
- * Returns the earliest position in the stream to which {@linkplain #seek(long) seeking}
- * may be performed.
- *
- * @return the earliest legal position for seeking.
- */
- @Override
- public final long getFlushedPosition() {
- return getStreamPosition() - buffer.position();
- }
-
- /**
- * Push back the last processed byte. This is used when a call to {@link #readBit()}
- * did not used every bits in a byte, or when {@link #readLine()} checked for the
- * Windows-style of EOL.
- */
- private void pushBack() {
- buffer.position(buffer.position() - 1);
- }
-
- /**
- * Returns the current bit offset, as an integer between 0 and 7 inclusive.
- *
- * <p>According {@link ImageInputStream} contract, the bit offset shall be reset to 0 by every call to
- * any {@code read} method except {@code readBit()} and {@link #readBits(int)}.</p>
- *
- * @return The bit offset of the stream.
- */
- @Override
- public final int getBitOffset() {
- final long currentPosition = getStreamPosition();
- if ((bitPosition >>> BIT_OFFSET_SIZE) != currentPosition) {
- bitPosition = currentPosition << BIT_OFFSET_SIZE;
- }
- return (int) (bitPosition & (Byte.SIZE - 1));
- }
-
- /**
- * Sets the bit offset to the given value.
- *
- * @param bitOffset The new bit offset of the stream.
- */
- @Override
- public final void setBitOffset(final int bitOffset) {
- ensureBetween("bitOffset", 0, Byte.SIZE - 1, bitOffset);
- bitPosition = (getStreamPosition() << BIT_OFFSET_SIZE) | bitOffset;
- }
-
- /**
- * Reads a single bit from the stream. The bit to be read depends on the
- * {@linkplain #getBitOffset() current bit offset}.
- *
- * @return The value of the next bit from the stream.
- * @throws IOException If an error occurred while reading (including EOF).
- */
- @Override
- public final int readBit() throws IOException {
- return (int) (readBits(1) & 1);
- }
-
- /**
- * Reads many bits from the stream. The first bit to be read depends on the
- * {@linkplain #getBitOffset() current bit offset}.
- *
- * @param numBits The number of bits to read.
- * @return The value of the next bits from the stream.
- * @throws IOException If an error occurred while reading (including EOF).
- */
- @Override
- public final long readBits(int numBits) throws IOException {
- ensureBetween("numBits", 0, Long.SIZE, numBits);
- if (numBits == 0) {
- return 0;
- }
- /*
- * Reads the bits available in the next bytes (all of them if bitOffset == 0)
- * and compute the number of bits that still need to be read. That number may
- * be negative if we have read too many bits.
- */
- final int bitOffset = getBitOffset();
- long value = readByte() & (0xFF >>> bitOffset);
- numBits -= (Byte.SIZE - bitOffset);
- while (numBits > 0) {
- value = (value << Byte.SIZE) | readUnsignedByte();
- numBits -= Byte.SIZE;
- }
- if (numBits != 0) {
- value >>>= (-numBits); // Discard the unwanted bits.
- numBits += Byte.SIZE;
- pushBack();
- }
- setBitOffset(numBits);
- return value;
- }
-
- /**
* Reads a byte from the stream and returns a {@code true} if it is nonzero, {@code false} otherwise.
* The implementation is as below:
*
@@ -426,31 +293,6 @@ loop: while ((c = read()) >= 0) {
}
/**
- * Pushes the current stream position onto a stack of marked positions.
- */
- @Override
- public final void mark() {
- mark = new Mark(getStreamPosition(), (byte) getBitOffset(), mark);
- }
-
- /**
- * Resets the current stream byte and bit positions from the stack of marked positions.
- * An {@code IOException} will be thrown if the previous marked position lies in the
- * discarded portion of the stream.
- *
- * @throws IOException If an I/O error occurs.
- */
- @Override
- public final void reset() throws IOException {
- if (mark == null) {
- throw new IOException("No marked position.");
- }
- seek(mark.position);
- setBitOffset(mark.bitOffset);
- mark = mark.next;
- }
-
- /**
* Discards the initial position of the stream prior to the current stream position.
* The implementation is as below:
*
@@ -466,47 +308,6 @@ loop: while ((c = read()) >= 0) {
}
/**
- * Discards the initial portion of the stream prior to the indicated position.
- * Attempting to {@linkplain #seek(long) seek} to an offset within the flushed
- * portion of the stream will result in an {@link IndexOutOfBoundsException}.
- *
- * <p>This method moves the data starting at the given position to the beginning of the {@link #buffer},
- * thus making more room for new data before the data at the given position is discarded.</p>
- *
- * @param position The length of the stream prefix that may be flushed.
- * @throws IOException If an I/O error occurred.
- */
- @Override
- public final void flushBefore(final long position) throws IOException {
- final long bufferOffset = getFlushedPosition();
- final long currentPosition = getStreamPosition();
- if (position < bufferOffset || position > currentPosition) {
- throw new IndexOutOfBoundsException(Errors.format(Errors.Keys.ValueOutOfRange_4,
- "position", bufferOffset, currentPosition, position));
- }
- final int n = (int) (position - bufferOffset);
- final int p = buffer.position() - n;
- final int r = buffer.limit() - n;
- buffer.position(n); // Number of bytes to forget.
- buffer.compact().position(p).limit(r);
- setStreamPosition(currentPosition);
-
- // Discard obolete marks.
- Mark parent = null;
- for (Mark m = mark; m != null; m = m.next) {
- if (m.position < position) {
- if (parent != null) {
- parent.next = null;
- } else {
- mark = null;
- }
- break;
- }
- parent = m;
- }
- }
-
- /**
* Synonymous of {@link #isCachedMemory()} since the caching behavior of this class is uniquely determined
* by the policy that we choose for {@code isCachedMemory()}. This class never creates temporary files.
*
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java [UTF-8] Sun Apr 27 20:22:58 2014
@@ -88,7 +88,7 @@ public abstract class DataStoreProvider
* // probably not a File, URL, URI, InputStream neither a ReadableChannel.
* return ProbeResult.UNSUPPORTED_STORAGE;
* }
- * if (buffer.remaining() < Integer.SIZE / Byte.SIZE) {
+ * if (buffer.remaining() < Integer.BYTES) {
* // If the buffer does not contain enough bytes for the integer type, this is not
* // necessarily because the file is truncated. It may be because the data were not
* // yet available at the time this method has been invoked.
Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java [UTF-8] Sun Apr 27 20:22:58 2014
@@ -100,7 +100,7 @@ public class ProbeResult implements Seri
* if (buffer == null) {
* return ProbeResult.UNSUPPORTED_STORAGE;
* }
- * if (buffer.remaining() < Integer.SIZE / Byte.SIZE) {
+ * if (buffer.remaining() < Integer.BYTES) {
* return ProbeResult.INSUFFICIENT_BYTES;
* }
* // Other verifications here.
Modified: sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java [UTF-8] Sun Apr 27 20:22:58 2014
@@ -16,14 +16,11 @@
*/
package org.apache.sis.internal.storage;
-import java.util.Random;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
-import org.apache.sis.test.TestUtilities;
-import org.apache.sis.test.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -35,28 +32,19 @@ import static org.junit.Assert.*;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.07)
- * @version 0.4
+ * @version 0.5
* @module
*/
-public final strictfp class ChannelDataInputTest extends TestCase {
+public final strictfp class ChannelDataInputTest extends ChannelDataTestCase {
/**
- * The maximal size of the arrays to be used for the tests, in bytes.
+ * The implementation to test.
*/
- private static final int ARRAY_MAX_SIZE = 256;
+ private ChannelDataInput testedStream;
/**
- * Creates an array filled with random values.
- *
- * @param length The length of the array to create.
- * @param random The random number generator to use.
+ * A stream to use as a reference implementation.
*/
- static byte[] createRandomArray(final int length, final Random random) {
- final byte[] array = new byte[length];
- for (int i=0; i<length; i++) {
- array[i] = (byte) random.nextInt(256);
- }
- return array;
- }
+ private DataInput referenceStream;
/**
* Fills a buffer with random data and compare the result with a standard image input stream.
@@ -67,90 +55,80 @@ public final strictfp class ChannelDataI
*/
@Test
public void testAllReadMethods() throws IOException {
- final Random random = TestUtilities.createRandomNumberGenerator();
- final byte[] array = createRandomArray(ARRAY_MAX_SIZE * 1024, random);
- compareStreamToBuffer(random, array.length,
- new DataInputStream(new ByteArrayInputStream(array)),
- new ChannelDataInput("testAllReadMethods",
- new DripByteChannel(array, random, 1, 1024),
- ByteBuffer.allocate(random.nextInt(ARRAY_MAX_SIZE / 4) + (Double.SIZE / Byte.SIZE)), false));
+ final byte[] array = createRandomArray(STREAM_LENGTH);
+ referenceStream = new DataInputStream(new ByteArrayInputStream(array));
+ testedStream = new ChannelDataInput("testAllReadMethods", new DripByteChannel(array, random, 1, 1024),
+ ByteBuffer.allocate(random.nextInt(BUFFER_MAX_CAPACITY) + (Double.SIZE / Byte.SIZE)), false);
+ transferRandomData(testedStream, array.length - ARRAY_MAX_LENGTH, 16);
}
/**
- * Compares the data returned by the given input to the data returned by the given buffer.
- *
- * @param random A random number generator for executing the test.
- * @param length Number of bytes in the {@code r} stream.
- * @param data A stream over all expected data.
- * @param input The instance to test.
- * @throws IOException Should never happen.
- */
- private static void compareStreamToBuffer(final Random random, int length,
- final DataInput data, final ChannelDataInput input) throws IOException
- {
- length -= ARRAY_MAX_SIZE; // Margin against buffer underflow.
- while (input.getStreamPosition() < length) {
- final int operation = random.nextInt(16);
- switch (operation) {
- default: throw new AssertionError(operation);
- case 0: assertEquals("readByte()", data.readByte(), input.readByte()); break;
- case 1: assertEquals("readShort()", data.readShort(), input.readShort()); break;
- case 2: assertEquals("readUnsignedShort()", data.readUnsignedShort(), input.readUnsignedShort()); break;
- case 3: assertEquals("readChar()", data.readChar(), input.readChar()); break;
- case 4: assertEquals("readInt()", data.readInt(), input.readInt()); break;
- case 5: assertEquals("readUnsignedInt()", data.readInt() & 0xFFFFFFFFL, input.readUnsignedInt()); break;
- case 6: assertEquals("readLong()", data.readLong(), input.readLong()); break;
- case 7: assertEquals("readFloat()", data.readFloat(), input.readFloat(), 0f); break;
- case 8: assertEquals("readDouble()", data.readDouble(), input.readDouble(), 0d); break;
- case 9: {
- final int n = random.nextInt(ARRAY_MAX_SIZE);
- final byte[] tmp = new byte[n];
- data.readFully(tmp);
- assertArrayEquals("readBytes(int)", tmp, input.readBytes(n));
- break;
- }
- case 10: {
- final int n = random.nextInt(ARRAY_MAX_SIZE / (Character.SIZE / Byte.SIZE));
- final char[] tmp = new char[n];
- for (int i=0; i<n; i++) tmp[i] = data.readChar();
- assertArrayEquals("readChars(int)", tmp, input.readChars(n));
- break;
- }
- case 11: {
- final int n = random.nextInt(ARRAY_MAX_SIZE / (Short.SIZE / Byte.SIZE));
- final short[] tmp = new short[n];
- for (int i=0; i<n; i++) tmp[i] = data.readShort();
- assertArrayEquals("readShorts(int)", tmp, input.readShorts(n));
- break;
- }
- case 12: {
- final int n = random.nextInt(ARRAY_MAX_SIZE / (Integer.SIZE / Byte.SIZE));
- final int[] tmp = new int[n];
- for (int i=0; i<n; i++) tmp[i] = data.readInt();
- assertArrayEquals("readInts(int)", tmp, input.readInts(n));
- break;
- }
- case 13: {
- final int n = random.nextInt(ARRAY_MAX_SIZE / (Long.SIZE / Byte.SIZE));
- final long[] tmp = new long[n];
- for (int i=0; i<n; i++) tmp[i] = data.readLong();
- assertArrayEquals("readLongs(int)", tmp, input.readLongs(n));
- break;
- }
- case 14: {
- final int n = random.nextInt(ARRAY_MAX_SIZE / (Float.SIZE / Byte.SIZE));
- final float[] tmp = new float[n];
- for (int i=0; i<n; i++) tmp[i] = data.readFloat();
- assertArrayEquals("readFloats(int)", tmp, input.readFloats(n), 0);
- break;
- }
- case 15: {
- final int n = random.nextInt(ARRAY_MAX_SIZE / (Double.SIZE / Byte.SIZE));
- final double[] tmp = new double[n];
- for (int i=0; i<n; i++) tmp[i] = data.readDouble();
- assertArrayEquals("readDoubles(int)", tmp, input.readDoubles(n), 0);
- break;
- }
+ * Reads a random unit of data using a method selected randomly.
+ * This method is invoked (indirectly) by {@link #testAllReadMethods()}.
+ */
+ @Override
+ final void transferRandomData(final int operation) throws IOException {
+ final ChannelDataInput t = testedStream;
+ final DataInput r = referenceStream;
+ switch (operation) {
+ default: throw new AssertionError(operation);
+ case 0: assertEquals("readByte()", r.readByte(), t.readByte()); break;
+ case 1: assertEquals("readShort()", r.readShort(), t.readShort()); break;
+ case 2: assertEquals("readUnsignedShort()", r.readUnsignedShort(), t.readUnsignedShort()); break;
+ case 3: assertEquals("readChar()", r.readChar(), t.readChar()); break;
+ case 4: assertEquals("readInt()", r.readInt(), t.readInt()); break;
+ case 5: assertEquals("readUnsignedInt()", r.readInt() & 0xFFFFFFFFL, t.readUnsignedInt()); break;
+ case 6: assertEquals("readLong()", r.readLong(), t.readLong()); break;
+ case 7: assertEquals("readFloat()", r.readFloat(), t.readFloat(), 0f); break;
+ case 8: assertEquals("readDouble()", r.readDouble(), t.readDouble(), 0d); break;
+ case 9: {
+ final int n = random.nextInt(ARRAY_MAX_LENGTH);
+ final byte[] tmp = new byte[n];
+ r.readFully(tmp);
+ assertArrayEquals("readBytes(int)", tmp, t.readBytes(n));
+ break;
+ }
+ case 10: {
+ final int n = random.nextInt(ARRAY_MAX_LENGTH / (Character.SIZE / Byte.SIZE));
+ final char[] tmp = new char[n];
+ for (int i=0; i<n; i++) tmp[i] = r.readChar();
+ assertArrayEquals("readChars(int)", tmp, t.readChars(n));
+ break;
+ }
+ case 11: {
+ final int n = random.nextInt(ARRAY_MAX_LENGTH / (Short.SIZE / Byte.SIZE));
+ final short[] tmp = new short[n];
+ for (int i=0; i<n; i++) tmp[i] = r.readShort();
+ assertArrayEquals("readShorts(int)", tmp, t.readShorts(n));
+ break;
+ }
+ case 12: {
+ final int n = random.nextInt(ARRAY_MAX_LENGTH / (Integer.SIZE / Byte.SIZE));
+ final int[] tmp = new int[n];
+ for (int i=0; i<n; i++) tmp[i] = r.readInt();
+ assertArrayEquals("readInts(int)", tmp, t.readInts(n));
+ break;
+ }
+ case 13: {
+ final int n = random.nextInt(ARRAY_MAX_LENGTH / (Long.SIZE / Byte.SIZE));
+ final long[] tmp = new long[n];
+ for (int i=0; i<n; i++) tmp[i] = r.readLong();
+ assertArrayEquals("readLongs(int)", tmp, t.readLongs(n));
+ break;
+ }
+ case 14: {
+ final int n = random.nextInt(ARRAY_MAX_LENGTH / (Float.SIZE / Byte.SIZE));
+ final float[] tmp = new float[n];
+ for (int i=0; i<n; i++) tmp[i] = r.readFloat();
+ assertArrayEquals("readFloats(int)", tmp, t.readFloats(n), 0);
+ break;
+ }
+ case 15: {
+ final int n = random.nextInt(ARRAY_MAX_LENGTH / (Double.SIZE / Byte.SIZE));
+ final double[] tmp = new double[n];
+ for (int i=0; i<n; i++) tmp[i] = r.readDouble();
+ assertArrayEquals("readDoubles(int)", tmp, t.readDoubles(n), 0);
+ break;
}
}
}
@@ -162,7 +140,6 @@ public final strictfp class ChannelDataI
*/
@Test
public void testReadString() throws IOException {
- final Random random = TestUtilities.createRandomNumberGenerator();
final String expected = "お元気ですか";
final byte[] array = expected.getBytes("UTF-8");
assertEquals(expected.length()*3, array.length); // Sanity check.
@@ -181,9 +158,8 @@ public final strictfp class ChannelDataI
*/
@Test
public void testSeekOnForwardOnlyChannel() throws IOException {
- final Random random = TestUtilities.createRandomNumberGenerator();
int length = random.nextInt(2048) + 1024;
- final byte[] array = createRandomArray(length, random);
+ final byte[] array = createRandomArray(length);
length -= (Long.SIZE / Byte.SIZE); // Safety against buffer underflow.
final ByteBuffer buffer = ByteBuffer.wrap(array);
final ChannelDataInput input = new ChannelDataInput("testSeekOnForwardOnlyChannel",
@@ -205,9 +181,8 @@ public final strictfp class ChannelDataI
*/
@Test
public void testPrefetch() throws IOException {
- final Random random = TestUtilities.createRandomNumberGenerator();
final int length = random.nextInt(256) + 128;
- final byte[] array = createRandomArray(length, random);
+ final byte[] array = createRandomArray(length);
final ByteBuffer buffer = ByteBuffer.allocate(random.nextInt(64) + 16);
final ChannelDataInput input = new ChannelDataInput("testPrefetch",
new DripByteChannel(array, random, 1, 64), buffer, false);
Modified: sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java?rev=1590484&r1=1590483&r2=1590484&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java [UTF-8] Sun Apr 27 20:22:58 2014
@@ -17,7 +17,6 @@
package org.apache.sis.internal.storage;
import java.util.Arrays;
-import java.util.Random;
import java.nio.ByteOrder;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
@@ -26,8 +25,6 @@ import java.io.IOException;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import org.apache.sis.test.DependsOn;
-import org.apache.sis.test.TestCase;
-import org.apache.sis.test.TestUtilities;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -39,15 +36,20 @@ import static org.junit.Assert.*;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.07)
- * @version 0.3
+ * @version 0.5
* @module
*/
@DependsOn(ChannelDataInputTest.class)
-public final strictfp class ChannelImageInputStreamTest extends TestCase {
+public final strictfp class ChannelImageInputStreamTest extends ChannelDataTestCase {
/**
- * The maximal size of the arrays to be used for the tests, in bytes.
+ * The implementation to test.
*/
- private static final int ARRAY_MAX_SIZE = 512;
+ private ChannelImageInputStream testedStream;
+
+ /**
+ * A stream to use as a reference implementation.
+ */
+ private ImageInputStream referenceStream;
/**
* Fills a buffer with random data and compares the result with a standard image input stream.
@@ -58,134 +60,125 @@ public final strictfp class ChannelImage
*/
@Test
public void testWithRandomData() throws IOException {
- long position = 0;
- int bitOffset = 0;
- int operation = 0;
- final ByteBuffer buffer = ByteBuffer.allocate(128);
- final Random random = TestUtilities.createRandomNumberGenerator();
+ final ByteBuffer buffer = ByteBuffer.allocate(BUFFER_MAX_CAPACITY);
final ByteOrder byteOrder = random.nextBoolean() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
- final byte[] data = ChannelDataInputTest.createRandomArray(512 * 1024, random);
- final ImageInputStream r = ImageIO.createImageInputStream(new ByteArrayInputStream(data));
- final ImageInputStream t = new ChannelImageInputStream("Test data",
- Channels.newChannel(new ByteArrayInputStream(data)), buffer, false);
- try {
- r.setByteOrder(byteOrder);
- t.setByteOrder(byteOrder);
- while ((position = r.getStreamPosition()) < data.length - ARRAY_MAX_SIZE) {
- bitOffset = r.getBitOffset();
- operation = random.nextInt(24);
- switch (operation) {
- default: throw new AssertionError(operation);
- case 0: assertEquals("read()", r.read(), t.read()); break;
- case 1: assertEquals("readBoolean()", r.readBoolean(), t.readBoolean()); break;
- case 2: assertEquals("readChar()", r.readChar(), t.readChar()); break;
- case 3: assertEquals("readByte()", r.readByte(), t.readByte()); break;
- case 4: assertEquals("readShort()", r.readShort(), t.readShort()); break;
- case 5: assertEquals("readUnsignedShort()", r.readUnsignedShort(), t.readUnsignedShort()); break;
- case 6: assertEquals("readInt()", r.readInt(), t.readInt()); break;
- case 7: assertEquals("readUnsignedInt()", r.readUnsignedInt(), t.readUnsignedInt()); break;
- case 8: assertEquals("readLong()", r.readLong(), t.readLong()); break;
- case 9: assertEquals("readFloat()", r.readFloat(), t.readFloat(), 0f); break;
- case 10: assertEquals("readDouble()", r.readDouble(), t.readDouble(), 0d); break;
- case 11: assertEquals("readBit()", r.readBit(), t.readBit()); break;
- case 12: {
- final int n = random.nextInt(Long.SIZE + 1);
- assertEquals("readBits(" + n + ')', r.readBits(n), t.readBits(n));
- break;
- }
- case 13: {
- final int length = random.nextInt(ARRAY_MAX_SIZE);
- final byte[] actual = new byte[length];
- final int n = t.read(actual);
- assertFalse("Reached EOF", n < 0);
- final byte[] expected = new byte[n];
- r.readFully(expected);
- assertArrayEquals("read(byte[])", expected, actual);
- break;
- }
- case 14: {
- final int length = random.nextInt(ARRAY_MAX_SIZE);
- final byte[] expected = new byte[length]; r.readFully(expected);
- final byte[] actual = new byte[length]; t.readFully(actual);
- assertArrayEquals("readFully(byte[])", expected, actual);
- break;
- }
- case 15: {
- final int length = random.nextInt(ARRAY_MAX_SIZE * Byte.SIZE / Character.SIZE);
- final char[] expected = new char[length]; r.readFully(expected, 0, length);
- final char[] actual = new char[length]; t.readFully(actual, 0, length);
- assertArrayEquals("readFully(char[])", expected, actual);
- break;
- }
- case 16: {
- final int length = random.nextInt(ARRAY_MAX_SIZE * Byte.SIZE / Short.SIZE);
- final short[] expected = new short[length]; r.readFully(expected, 0, length);
- final short[] actual = new short[length]; t.readFully(actual, 0, length);
- assertArrayEquals("readFully(short[])", expected, actual);
- break;
- }
- case 17: {
- final int length = random.nextInt(ARRAY_MAX_SIZE * Byte.SIZE / Integer.SIZE);
- final int[] expected = new int[length]; r.readFully(expected, 0, length);
- final int[] actual = new int[length]; t.readFully(actual, 0, length);
- assertArrayEquals("readFully(int[])", expected, actual);
- break;
- }
- case 18: {
- final int length = random.nextInt(ARRAY_MAX_SIZE * Byte.SIZE / Long.SIZE);
- final long[] expected = new long[length]; r.readFully(expected, 0, length);
- final long[] actual = new long[length]; t.readFully(actual, 0, length);
- assertArrayEquals("readFully(long[])", expected, actual);
- break;
- }
- case 19: {
- final int length = random.nextInt(ARRAY_MAX_SIZE * Byte.SIZE / Float.SIZE);
- final float[] expected = new float[length]; r.readFully(expected, 0, length);
- final float[] actual = new float[length]; t.readFully(actual, 0, length);
- assertTrue("readFully(float[])", Arrays.equals(expected, actual));
- break;
- }
- case 20: {
- final int length = random.nextInt(ARRAY_MAX_SIZE * Byte.SIZE / Double.SIZE);
- final double[] expected = new double[length]; r.readFully(expected, 0, length);
- final double[] actual = new double[length]; t.readFully(actual, 0, length);
- assertTrue("readFully(double[])", Arrays.equals(expected, actual));
- break;
- }
- case 21: {
- final long length = random.nextInt(ARRAY_MAX_SIZE);
- final long n = t.skipBytes(length);
- assertFalse("Reached EOF", n < 0);
- r.readFully(new byte[(int) n]);
- assertEquals("skipBytes(int)", r.getStreamPosition(), t.getStreamPosition());
- break;
- }
- case 22: {
- long flushedPosition = StrictMath.max(r.getFlushedPosition(), t.getFlushedPosition());
- flushedPosition += random.nextInt(1 + (int) (r.getStreamPosition() - flushedPosition));
- r.flushBefore(flushedPosition);
- t.flushBefore(flushedPosition);
- break;
- }
- case 23: {
- r.flush();
- t.flush();
- break;
- }
- }
- assertEquals("getStreamPosition()", r.getStreamPosition(), t.getStreamPosition());
- assertEquals("getBitOffset()", r.getBitOffset(), t.getBitOffset());
- }
- } catch (AssertionError e) {
- out.println("Position: " + position);
- out.println("Bit offset: " + bitOffset);
- out.println("Byte order: " + byteOrder);
- out.println("Operation: " + operation);
- out.println("Exception: " + e.getLocalizedMessage());
- throw e;
- } finally {
- t.close();
- r.close();
+ final byte[] data = createRandomArray(STREAM_LENGTH);
+ referenceStream = ImageIO.createImageInputStream(new ByteArrayInputStream(data));
+ referenceStream.setByteOrder(byteOrder);
+ testedStream = new ChannelImageInputStream("testWithRandomData",
+ Channels.newChannel(new ByteArrayInputStream(data)), buffer, false);
+ testedStream.setByteOrder(byteOrder);
+ transferRandomData(testedStream, data.length - ARRAY_MAX_LENGTH, 24);
+ }
+
+ /**
+ * Reads a random unit of data using a method selected randomly.
+ * This method is invoked (indirectly) by {@link #testWithRandomData()}.
+ */
+ @Override
+ final void transferRandomData(final int operation) throws IOException {
+ final ChannelImageInputStream t = testedStream;
+ final ImageInputStream r = referenceStream;
+ switch (operation) {
+ default: throw new AssertionError(operation);
+ case 0: assertEquals("read()", r.read(), t.read()); break;
+ case 1: assertEquals("readBoolean()", r.readBoolean(), t.readBoolean()); break;
+ case 2: assertEquals("readChar()", r.readChar(), t.readChar()); break;
+ case 3: assertEquals("readByte()", r.readByte(), t.readByte()); break;
+ case 4: assertEquals("readShort()", r.readShort(), t.readShort()); break;
+ case 5: assertEquals("readUnsignedShort()", r.readUnsignedShort(), t.readUnsignedShort()); break;
+ case 6: assertEquals("readInt()", r.readInt(), t.readInt()); break;
+ case 7: assertEquals("readUnsignedInt()", r.readUnsignedInt(), t.readUnsignedInt()); break;
+ case 8: assertEquals("readLong()", r.readLong(), t.readLong()); break;
+ case 9: assertEquals("readFloat()", r.readFloat(), t.readFloat(), 0f); break;
+ case 10: assertEquals("readDouble()", r.readDouble(), t.readDouble(), 0d); break;
+ case 11: assertEquals("readBit()", r.readBit(), t.readBit()); break;
+ case 12: {
+ final int n = random.nextInt(Long.SIZE + 1);
+ assertEquals("readBits(" + n + ')', r.readBits(n), t.readBits(n));
+ break;
+ }
+ case 13: {
+ final int length = random.nextInt(ARRAY_MAX_LENGTH);
+ final byte[] actual = new byte[length];
+ final int n = t.read(actual);
+ assertFalse("Reached EOF", n < 0);
+ final byte[] expected = new byte[n];
+ r.readFully(expected);
+ assertArrayEquals("read(byte[])", expected, actual);
+ break;
+ }
+ case 14: {
+ final int length = random.nextInt(ARRAY_MAX_LENGTH);
+ final byte[] expected = new byte[length]; r.readFully(expected);
+ final byte[] actual = new byte[length]; t.readFully(actual);
+ assertArrayEquals("readFully(byte[])", expected, actual);
+ break;
+ }
+ case 15: {
+ final int length = random.nextInt(ARRAY_MAX_LENGTH / (Character.SIZE / Byte.SIZE));
+ final char[] expected = new char[length]; r.readFully(expected, 0, length);
+ final char[] actual = new char[length]; t.readFully(actual, 0, length);
+ assertArrayEquals("readFully(char[])", expected, actual);
+ break;
+ }
+ case 16: {
+ final int length = random.nextInt(ARRAY_MAX_LENGTH / (Short.SIZE / Byte.SIZE));
+ final short[] expected = new short[length]; r.readFully(expected, 0, length);
+ final short[] actual = new short[length]; t.readFully(actual, 0, length);
+ assertArrayEquals("readFully(short[])", expected, actual);
+ break;
+ }
+ case 17: {
+ final int length = random.nextInt(ARRAY_MAX_LENGTH / (Integer.SIZE / Byte.SIZE));
+ final int[] expected = new int[length]; r.readFully(expected, 0, length);
+ final int[] actual = new int[length]; t.readFully(actual, 0, length);
+ assertArrayEquals("readFully(int[])", expected, actual);
+ break;
+ }
+ case 18: {
+ final int length = random.nextInt(ARRAY_MAX_LENGTH / (Long.SIZE / Byte.SIZE));
+ final long[] expected = new long[length]; r.readFully(expected, 0, length);
+ final long[] actual = new long[length]; t.readFully(actual, 0, length);
+ assertArrayEquals("readFully(long[])", expected, actual);
+ break;
+ }
+ case 19: {
+ final int length = random.nextInt(ARRAY_MAX_LENGTH / (Float.SIZE / Byte.SIZE));
+ final float[] expected = new float[length]; r.readFully(expected, 0, length);
+ final float[] actual = new float[length]; t.readFully(actual, 0, length);
+ assertTrue("readFully(float[])", Arrays.equals(expected, actual));
+ break;
+ }
+ case 20: {
+ final int length = random.nextInt(ARRAY_MAX_LENGTH / (Double.SIZE / Byte.SIZE));
+ final double[] expected = new double[length]; r.readFully(expected, 0, length);
+ final double[] actual = new double[length]; t.readFully(actual, 0, length);
+ assertTrue("readFully(double[])", Arrays.equals(expected, actual));
+ break;
+ }
+ case 21: {
+ final long length = random.nextInt(ARRAY_MAX_LENGTH);
+ final long n = t.skipBytes(length);
+ assertFalse("Reached EOF", n < 0);
+ r.readFully(new byte[(int) n]);
+ assertEquals("skipBytes(int)", r.getStreamPosition(), t.getStreamPosition());
+ break;
+ }
+ case 22: {
+ long flushedPosition = StrictMath.max(r.getFlushedPosition(), t.getFlushedPosition());
+ flushedPosition += random.nextInt(1 + (int) (r.getStreamPosition() - flushedPosition));
+ r.flushBefore(flushedPosition);
+ t.flushBefore(flushedPosition);
+ break;
+ }
+ case 23: {
+ r.flush();
+ t.flush();
+ break;
+ }
}
+ assertEquals("getStreamPosition()", r.getStreamPosition(), t.getStreamPosition());
+ assertEquals("getBitOffset()", r.getBitOffset(), t.getBitOffset());
}
}
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=1590484&r1=1590483&r2=1590484&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] Sun Apr 27 20:22:58 2014
@@ -26,13 +26,15 @@ import org.junit.BeforeClass;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.4
+ * @version 0.5
* @module
*/
@Suite.SuiteClasses({
org.apache.sis.internal.storage.IOUtilitiesTest.class,
org.apache.sis.internal.storage.ChannelDataInputTest.class,
+ org.apache.sis.internal.storage.ChannelDataOutputTest.class,
org.apache.sis.internal.storage.ChannelImageInputStreamTest.class,
+ org.apache.sis.internal.storage.ChannelImageOutputStreamTest.class,
org.apache.sis.storage.ProbeResultTest.class,
org.apache.sis.storage.StorageConnectorTest.class,
org.apache.sis.internal.storage.xml.MimeTypeDetectorTest.class,