changeset 411:2e537136b40e

Fixes/updates for nio2-b93 - Allow building on Windows with cygwin - Bundled FileTypeDetectors return invalid content types - Files.probeContentType throws UnsatifiedLinkException if invoked before other methods - Path.createLink throws UOE on Windows XP/2003 - Typo in CompletionHandler spec - AsynchronousFileChannel missing description of executor parameter
author alanb
date Tue, 15 Jul 2008 15:09:41 +0100
parents c5ebc4603dc6
children 0844644a266a
files make/java/nio/FILES_java.gmk make/java/nio/Makefile src/share/classes/java/nio/channels/AsynchronousFileChannel.java src/share/classes/java/nio/channels/CompletionHandler.java src/share/classes/sun/nio/fs/AbstractFileTypeDetector.java src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java src/windows/classes/sun/nio/fs/WindowsPath.java test/java/nio/channels/AsynchronousFileChannel/Lock.java test/java/nio/file/Files/ForceLoad.java test/java/nio/file/attribute/NamedAttributeView/Basic.java
diffstat 11 files changed, 136 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/make/java/nio/FILES_java.gmk	Tue Jul 15 12:10:41 2008 +0100
+++ b/make/java/nio/FILES_java.gmk	Tue Jul 15 15:09:41 2008 +0100
@@ -233,6 +233,7 @@
 	sun/nio/cs/UTF_32LE_BOM.java \
 	sun/nio/cs/UTF_32Coder.java \
 	\
+	sun/nio/fs/AbstractFileTypeDetector.java \
 	sun/nio/fs/AbstractPoller.java \
 	sun/nio/fs/AbstractNamedAttributeView.java \
 	sun/nio/fs/AbstractWatchKey.java \
--- a/make/java/nio/Makefile	Tue Jul 15 12:10:41 2008 +0100
+++ b/make/java/nio/Makefile	Tue Jul 15 15:09:41 2008 +0100
@@ -821,7 +821,7 @@
 
 $(SCH_GEN)/SocketOptionRegistry.java: $(GENSOR_EXE)
 	$(prep-target)
-	NAWK=$(NAWK) SH=$(SH) $(SH) -e addNotices.sh $(SOR_COPYRIGHT_YEARS) > $@
+	NAWK="$(NAWK)" SH="$(SH)" $(SH) -e addNotices.sh $(SOR_COPYRIGHT_YEARS) > $@
 	$(GENSOR_EXE) >> $@
 
 # 
@@ -841,7 +841,7 @@
 
 $(SFS_GEN)/UnixConstants.java: $(GENUC_EXE)
 	$(prep-target)
-	NAWK=$(NAWK) SH=$(SH) $(SH) -e addNotices.sh $(GENUC_COPYRIGHT_YEARS) > $@
+	NAWK="$(NAWK)" SH="$(SH)" $(SH) -e addNotices.sh $(GENUC_COPYRIGHT_YEARS) > $@
 	$(GENUC_EXE) >> $@
 
 GENSC_SRC = $(PLATFORM_SRC)/native/sun/nio/fs/genSolarisConstants.c
@@ -857,7 +857,7 @@
 
 $(SFS_GEN)/SolarisConstants.java: $(GENSC_EXE)
 	$(prep-target)
-	NAWK=$(NAWK) SH=$(SH) $(SH) -e addNotices.sh $(GENSC_COPYRIGHT_YEARS) > $@
+	NAWK="$(NAWK)" SH="$(SH)" $(SH) -e addNotices.sh $(GENSC_COPYRIGHT_YEARS) > $@
 	$(GENSC_EXE) >> $@
 
 #
--- a/src/share/classes/java/nio/channels/AsynchronousFileChannel.java	Tue Jul 15 12:10:41 2008 +0100
+++ b/src/share/classes/java/nio/channels/AsynchronousFileChannel.java	Tue Jul 15 15:09:41 2008 +0100
@@ -206,6 +206,17 @@
      * <p> An implementation may also support additional implementation-specific
      * options.
      *
+     * <p> The {@code executor} parameter is the {@link ExecutorService} to
+     * which tasks are submitted to handle I/O events and dispatch completion
+     * results for operations initiated on resulting channel.
+     * The nature of these tasks is highly implementation specific and so care
+     * should be taken when configuring the {@code Executor}. Minimally it
+     * should support an unbounded work queue and should not run tasks on the
+     * caller thread of the {@link ExecutorService#execute execute} method.
+     * {@link #close Closing} the channel results in the orderly {@link
+     * ExecutorService#shutdown shutdown} of the executor service. Shutting down
+     * the executor service by other means results in unspecified behavior.
+     *
      * <p> The {@code attrs} parameter is an optional array of file {@link Attribute
      * attributes} to set atomically when creating the file.
      *
--- a/src/share/classes/java/nio/channels/CompletionHandler.java	Tue Jul 15 12:10:41 2008 +0100
+++ b/src/share/classes/java/nio/channels/CompletionHandler.java	Tue Jul 15 15:09:41 2008 +0100
@@ -30,10 +30,10 @@
  *
  * <p> The asynchronous channels defined in this package allow a completion
  * handler to be specified to consume the result of an asynchronous operation.
- * The {@link #completed completed} is invoked when the I/O operation completes
- * successfully. The {@link #failed failed} method is invoked if the I/O
- * operations fails. The {@link #cancelled cancelled} is invoked when the I/O
- * operation is cancelled by invoking the {@link
+ * The {@link #completed completed} method is invoked when the I/O operation
+ * completes successfully. The {@link #failed failed} method is invoked if the
+ * I/O operations fails. The {@link #cancelled cancelled} method is invoked when
+ * the I/O operation is cancelled by invoking the {@link
  * java.util.concurrent.Future#cancel cancel} method. The implementations of
  * these methods should complete in a timely manner so as to avoid keeping the
  * invoking thread from dispatching to other completion handlers.
@@ -74,5 +74,4 @@
      *          The object attached to the I/O operation when it was initiated.
      */
     void cancelled(A attachment);
-
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/sun/nio/fs/AbstractFileTypeDetector.java	Tue Jul 15 15:09:41 2008 +0100
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.nio.fs;
+
+import java.nio.file.FileRef;
+import java.nio.file.spi.FileTypeDetector;
+import java.nio.file.spi.FileTypeDetector.Result;
+import java.io.IOException;
+
+/**
+ * Base implementation of FileTypeDetector
+ */
+
+public abstract class AbstractFileTypeDetector
+    extends FileTypeDetector
+{
+    protected AbstractFileTypeDetector() {
+        super();
+    }
+
+    /**
+     * Invokes the implProbeContentType method to guess the file's content type,
+     * and this validates that the content type's syntax is valid.
+     */
+    @Override
+    public final Result<String> probeContentType(FileRef file)
+       throws IOException
+    {
+        Result<String> result = implProbeContentType(file);
+        if (result != null) {
+            // check the content type
+            try {
+                new javax.activation.MimeType(result.get());
+            } catch (javax.activation.MimeTypeParseException ignore) {
+                result = null;
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Probes the given file to guess its content type.
+     */
+    protected abstract Result<String> implProbeContentType(FileRef file)
+        throws IOException;
+}
--- a/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java	Tue Jul 15 12:10:41 2008 +0100
+++ b/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java	Tue Jul 15 15:09:41 2008 +0100
@@ -25,7 +25,6 @@
 
 package sun.nio.fs;
 
-import java.nio.file.spi.FileTypeDetector;
 import java.nio.file.spi.FileTypeDetector.Result;
 import java.nio.file.FileRef;
 import java.io.IOException;
@@ -37,7 +36,7 @@
  */
 
 public class GnomeFileTypeDetector
-    extends FileTypeDetector
+    extends AbstractFileTypeDetector
 {
     // true if GNOME VFS initialized
     private static final boolean initialized;
@@ -47,7 +46,7 @@
     }
 
     @Override
-    public Result<String> probeContentType(FileRef obj)
+    public Result<String> implProbeContentType(FileRef obj)
        throws IOException
     {
         if (!initialized)
@@ -66,7 +65,6 @@
         if (mimeType == null)
             return null;
 
-        // assume syntax is correct
         final String result = new String(mimeType);
         return new Result<String>() {
             @Override
--- a/src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java	Tue Jul 15 12:10:41 2008 +0100
+++ b/src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java	Tue Jul 15 15:09:41 2008 +0100
@@ -26,7 +26,6 @@
 package sun.nio.fs;
 
 import java.nio.file.*;
-import java.nio.file.spi.FileTypeDetector;
 import java.nio.file.spi.FileTypeDetector.Result;
 import java.io.IOException;
 import java.security.AccessController;
@@ -37,14 +36,14 @@
  */
 
 public class RegistryFileTypeDetector
-    extends FileTypeDetector
+    extends AbstractFileTypeDetector
 {
     public RegistryFileTypeDetector() {
         super();
     }
 
     @Override
-    public Result<String> probeContentType(FileRef file)
+    public Result<String> implProbeContentType(FileRef file)
        throws IOException
     {
         if (!(file instanceof Path))
@@ -92,6 +91,8 @@
         AccessController.doPrivileged(new PrivilegedAction<Void>() {
             @Override
             public Void run() {
+                // nio.dll has dependency on net.dll
+                System.loadLibrary("net");
                 System.loadLibrary("nio");
                 return null;
         }});
--- a/src/windows/classes/sun/nio/fs/WindowsPath.java	Tue Jul 15 12:10:41 2008 +0100
+++ b/src/windows/classes/sun/nio/fs/WindowsPath.java	Tue Jul 15 15:09:41 2008 +0100
@@ -1009,10 +1009,6 @@
 
     @Override
     public Path createLink(Path obj) throws IOException {
-        if (!getFileSystem().supportsLinks()) {
-            throw new UnsupportedOperationException("Creating hard links links not supported");
-        }
-
         WindowsPath existing = checkPath(obj);
 
         // permission check
--- a/test/java/nio/channels/AsynchronousFileChannel/Lock.java	Tue Jul 15 12:10:41 2008 +0100
+++ b/test/java/nio/channels/AsynchronousFileChannel/Lock.java	Tue Jul 15 15:09:41 2008 +0100
@@ -271,8 +271,7 @@
             for (;;) {
 
                 // read command (ends with ";")
-                buf.rewind();
-                buf.limit(buf.capacity());
+                buf.clear();
                 int n, last = 0;
                 do {
                     n = sc.read(buf);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/nio/file/Files/ForceLoad.java	Tue Jul 15 15:09:41 2008 +0100
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4313887
+ * @summary Test library dependencies by invoking Files.probeContentType
+ *     before other methods that would cause nio.dll to be loaded.
+ */
+
+import java.nio.file.*;
+import java.io.IOException;
+
+public class ForceLoad {
+
+    public static void main(String[] args) throws IOException {
+        Files.probeContentType(Path.get("."));
+    }
+}
--- a/test/java/nio/file/attribute/NamedAttributeView/Basic.java	Tue Jul 15 12:10:41 2008 +0100
+++ b/test/java/nio/file/attribute/NamedAttributeView/Basic.java	Tue Jul 15 15:09:41 2008 +0100
@@ -71,7 +71,7 @@
             throw new RuntimeException("Unexpected size");
 
         // Test: read
-        buf.limit(buf.capacity()).rewind();
+        buf.clear();
         int nread = view.read(ATTR_NAME, buf);
         if (nread != size)
             throw new RuntimeException("Unexpected number of bytes read");
@@ -88,7 +88,7 @@
         }
 
         // Test: replace value
-        buf.limit(buf.capacity()).rewind();
+        buf.clear();
         buf.put(ATTR_VALUE2.getBytes()).flip();
         buf.get();
         size = buf.remaining();
@@ -106,7 +106,7 @@
             throw new RuntimeException("Attribute name in list");
 
         // Test: iterator's remove method
-        buf.limit(buf.capacity()).rewind();
+        buf.clear();
         buf.put(ATTR_VALUE.getBytes()).flip();
         view.write(ATTR_NAME, buf);
         Iterator<String> iter = view.list().iterator();