sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1490053 [2/2] - in /sis/branches/JDK6: ./ application/sis-app/ application/sis-webapp/ application/sis-webapp/src/main/webapp/ core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/ core/sis-build-helper/src/site/ core/sis-met...
Date Wed, 05 Jun 2013 22:30:49 GMT
Copied: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java
(from r1490042, sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java?p2=sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java&p1=sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java&r1=1490042&r2=1490053&rev=1490053&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java
[UTF-8] Wed Jun  5 22:30:47 2013
@@ -26,18 +26,16 @@ import java.net.URL;
 import java.net.URLDecoder;
 import java.net.URISyntaxException;
 import java.net.MalformedURLException;
-import java.nio.file.Path;
-import java.nio.file.Files;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.FileSystemNotFoundException;
-import java.nio.file.Paths;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.Static;
 import org.apache.sis.util.resources.Errors;
 
+// Related to JDK7
+import org.apache.sis.internal.jdk7.StandardCharsets;
+
 
 /**
  * Utility methods related to I/O operations. Many methods in this class accept arbitrary
{@link Object} argument
@@ -95,8 +93,6 @@ public final class IOUtilities extends S
         final String name;
         if (path instanceof File) {
             name = ((File) path).getName();
-        } else if (path instanceof Path) {
-            name = ((Path) path).getFileName().toString();
         } else {
             char separator = '/';
             if (path instanceof URL) {
@@ -134,7 +130,7 @@ public final class IOUtilities extends S
     public static String toString(final Object path) {
         // For the following types, the string that we want can be obtained only by toString(),
         // or the class is final so we know that the toString(à behavior can not be changed.
-        if (path instanceof CharSequence || path instanceof Path || path instanceof URL ||
path instanceof URI) {
+        if (path instanceof CharSequence || path instanceof URL || path instanceof URI) {
             return path.toString();
         }
         // While toString() would work too on the default implementation, the following
@@ -292,40 +288,6 @@ public final class IOUtilities extends S
     }
 
     /**
-     * Converts a {@link URL} to a {@link Path}. This is equivalent to a call to the standard
-     * {@link URL#toURI()} method followed by a call to the {@link Paths#get(URI)} static
method,
-     * except for the following functionalities:
-     *
-     * <ul>
-     *   <li>Optionally decodes the {@code "%XX"} sequences, where {@code "XX"} is
a number.</li>
-     *   <li>Converts various exceptions into subclasses of {@link IOException}.</li>
-     * </ul>
-     *
-     * @param  url The URL to convert, or {@code null}.
-     * @param  encoding If the URL is encoded in a {@code application/x-www-form-urlencoded}
-     *         MIME format, the character encoding (normally {@code "UTF-8"}). If the URL
is
-     *         not encoded, then {@code null}.
-     * @return The path for the given URL, or {@code null} if the given URL was null.
-     * @throws IOException if the URL can not be converted to a path.
-     *
-     * @see Paths#get(URI)
-     */
-    public static Path toPath(final URL url, final String encoding) throws IOException {
-        if (url == null) {
-            return null;
-        }
-        final URI uri = toURI(url, encoding);
-        try {
-            return Paths.get(uri);
-        } catch (IllegalArgumentException | FileSystemNotFoundException cause) {
-            final MalformedURLException e = new MalformedURLException(Exceptions.formatChainedMessages(
-                    null, Errors.format(Errors.Keys.IllegalArgumentValue_2, "URL", url),
cause));
-            e.initCause(cause);
-            throw e;
-        }
-    }
-
-    /**
      * Parses the following path as a {@link File} if possible, or a {@link URL} otherwise.
      * In the special case where the given {@code path} is a URL using the {@code "file"}
protocol,
      * the URL is converted to a {@link File} object using the given {@code encoding} for
decoding
@@ -405,9 +367,6 @@ public final class IOUtilities extends S
             }
             return Channels.newChannel((InputStream) input);
         }
-        if (input instanceof Path) {
-            return Files.newByteChannel((Path) input);
-        }
         if (input instanceof CharSequence) { // Needs to be before the check for File or
URL.
             input = toFileOrURL(input.toString(), encoding);
         }

Copied: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/AbstractDataStore.java
(from r1490042, sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/AbstractDataStore.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/AbstractDataStore.java?p2=sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/AbstractDataStore.java&p1=sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/AbstractDataStore.java&r1=1490042&r2=1490053&rev=1490053&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/AbstractDataStore.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/AbstractDataStore.java
[UTF-8] Wed Jun  5 22:30:47 2013
@@ -50,7 +50,7 @@ public abstract class AbstractDataStore 
      * Creates a new instance with initially no listener.
      */
     protected AbstractDataStore() {
-        locale = Locale.getDefault(Locale.Category.DISPLAY);
+        locale = Locale.getDefault();
         listeners = new WarningListeners<DataStore>(this);
     }
 

Copied: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
(from r1490042, sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java?p2=sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java&p1=sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java&r1=1490042&r2=1490053&rev=1490053&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
[UTF-8] Wed Jun  5 22:30:47 2013
@@ -20,6 +20,9 @@ import java.util.NoSuchElementException;
 import org.opengis.metadata.Metadata;
 import org.apache.sis.util.logging.WarningListener;
 
+// Related to JDK7
+import org.apache.sis.internal.jdk7.AutoCloseable;
+
 
 /**
  * A storage object which manage a series of features, coverages or sensor data.

Copied: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreConnection.java
(from r1490042, sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreConnection.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreConnection.java?p2=sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreConnection.java&p1=sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreConnection.java&r1=1490042&r2=1490053&rev=1490053&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreConnection.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreConnection.java
[UTF-8] Wed Jun  5 22:30:47 2013
@@ -38,6 +38,9 @@ import org.apache.sis.internal.storage.C
 import org.apache.sis.internal.storage.ChannelImageInputStream;
 import org.apache.sis.setup.OptionKey;
 
+// Related to JDK7
+import org.apache.sis.internal.jdk7.JDK7;
+
 
 /**
  * Information for creating a connection to a {@link DataStore} in read and/or write mode.
@@ -317,7 +320,7 @@ public class DataStoreConnection impleme
                 return (view != Void.TYPE) ? type.cast(view) : null;
             }
         } else {
-            views = new IdentityHashMap<>();
+            views = new IdentityHashMap<Class<?>, Object>();
         }
         /*
          * Special case for DataInput and ByteBuffer, because those values are created together.
@@ -531,27 +534,27 @@ public class DataStoreConnection impleme
          * DataInput and ImageInputStream are often the same instance. We must avoid duplicated
          * values because ImageInputStream.close() is not indempotent.
          */
-        final Map<AutoCloseable,Object> toClose = new IdentityHashMap<>(4);
+        final Map<Object,Object> toClose = new IdentityHashMap<Object,Object>(4);
         for (final Object value : views.values()) {
-            if (value instanceof AutoCloseable) {
-                toClose.put((AutoCloseable) value, null);
+            if (JDK7.isAutoCloseable(value)) {
+                toClose.put(value, null);
             }
         }
         toClose.remove(view);
         toClose.remove(storage);
         try {
             if (!toClose.isEmpty()) {
-                for (final AutoCloseable value : toClose.keySet()) {
-                    value.close();
+                for (final Object value : toClose.keySet()) {
+                    JDK7.close(value);
                 }
-            } else if (view == null && storage instanceof AutoCloseable) {
+            } else if (view == null && JDK7.isAutoCloseable(storage)) {
                 /*
                  * Close only if we didn't closed a view because closing an input stream
view
                  * automatically close the 'storage' if the former is a wrapper for the later.
                  * Since AutoCloseable.close() is not guaranteed to be indempotent, we should
                  * avoid to call it (indirectly) twice.
                  */
-                ((AutoCloseable) storage).close();
+                JDK7.close(storage);
             }
         } catch (Exception e) {
             throw new DataStoreException(e);

Modified: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreException.java?rev=1490053&r1=1490052&r2=1490053&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreException.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreException.java
[UTF-8] Wed Jun  5 22:30:47 2013
@@ -18,7 +18,7 @@ package org.apache.sis.storage;
 
 
 /**
- * Throws when a {@link DataStore} can not completed a read or write operation.
+ * Thrown when a {@link DataStore} can not complete a read or write operation.
  *
  * @author  Johann Sorel (Geomatys)
  * @since   0.3 (derived from geotk-3.10)

Modified: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java?rev=1490053&r1=1490052&r2=1490053&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/package-info.java
[UTF-8] Wed Jun  5 22:30:47 2013
@@ -16,9 +16,11 @@
  */
 
 /**
- * Place holder for future {@code DataStore} services.
+ * {@linkplain org.apache.sis.storage.DataStore Data store} base types for retrieving and
saving geospatial data
+ * in various storage formats.
  *
  * @author  Johann Sorel (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.10)
  * @version 0.3
  * @module

Modified: sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java?rev=1490053&r1=1490052&r2=1490053&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
[UTF-8] Wed Jun  5 22:30:47 2013
@@ -143,6 +143,23 @@ public final strictfp class ChannelDataI
     }
 
     /**
+     * Tests the {@link ChannelDataInput#readString(int, String)} method.
+     *
+     * @throws IOException Should never happen.
+     */
+    @Test
+    public void testReadString() throws IOException {
+        final String expected = "お元気ですか";
+        final byte[] array = expected.getBytes("UTF-8");
+        assertEquals(expected.length()*3, array.length); // Sanity check.
+        final ChannelDataInput input = new ChannelDataInput("testReadString",
+                Channels.newChannel(new ByteArrayInputStream(array)),
+                ByteBuffer.allocate(array.length + 4), false);
+        assertEquals(expected, input.readString(array.length, "UTF-8"));
+        assertFalse(input.buffer.hasRemaining());
+    }
+
+    /**
      * Tests {@link ChannelDataInput#seek(long)} on a channel that do not implement
      * {@link java.nio.channels.SeekableByteChannel}.
      *

Modified: sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java?rev=1490053&r1=1490052&r2=1490053&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] Wed Jun  5 22:30:47 2013
@@ -30,8 +30,10 @@ import org.junit.BeforeClass;
  * @module
  */
 @Suite.SuiteClasses({
+    org.apache.sis.internal.storage.IOUtilitiesTest.class,
     org.apache.sis.internal.storage.ChannelDataInputTest.class,
-    org.apache.sis.internal.storage.ChannelImageInputStreamTest.class
+    org.apache.sis.internal.storage.ChannelImageInputStreamTest.class,
+    org.apache.sis.storage.DataStoreConnectionTest.class
 })
 public final strictfp class StorageTestSuite extends TestSuite {
     /**



Mime
View raw message