8066258: Re-examine com.sun.nio.file to see if it should be a supported API
authoralanb
Mon, 30 May 2016 17:38:05 +0100
changeset 38742 4af80d6e9e4d
parent 38739 9e1bab71b60c
child 38743 c57fc9cfae33
8066258: Re-examine com.sun.nio.file to see if it should be a supported API Reviewed-by: chegar
jdk/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java
jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedCopyOption.java
jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedOpenOption.java
jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java
jdk/src/java.base/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java
jdk/src/java.base/share/classes/module-info.java
jdk/src/java.base/share/classes/sun/nio/fs/ExtendedOptions.java
jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java
jdk/src/java.base/solaris/classes/sun/nio/fs/SolarisWatchService.java
jdk/src/java.base/unix/classes/sun/nio/fs/UnixCopyFile.java
jdk/src/java.base/windows/classes/sun/nio/fs/WindowsChannelFactory.java
jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileCopy.java
jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java
jdk/src/java.base/windows/classes/sun/nio/fs/WindowsWatchService.java
jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedCopyOption.java
jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedOpenOption.java
jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java
jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java
jdk/src/jdk.unsupported/share/classes/module-info.java
jdk/test/java/nio/file/Files/InterruptCopy.java
jdk/test/java/nio/file/Files/SBC.java
jdk/test/java/nio/file/WatchService/FileTreeModifier.java
jdk/test/java/nio/file/WatchService/SensitivityModifier.java
jdk/test/java/nio/file/WatchService/WithSecurityManager.java
--- a/jdk/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -232,9 +232,11 @@
                 for (WatchEvent.Modifier modifier: modifiers) {
                     if (modifier == null)
                         return new NullPointerException();
-                    if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier)
-                        continue; // ignore
-                    return new UnsupportedOperationException("Modifier not supported");
+                    if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
+                            !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
+                            !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
+                        return new UnsupportedOperationException("Modifier not supported");
+                    }
                 }
             }
 
--- a/jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedCopyOption.java	Mon May 30 15:28:48 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.nio.file;
-
-import java.nio.file.CopyOption;
-
-/**
- * Defines <em>extended</em> copy options supported on some platforms
- * by Sun's provider implementation.
- *
- * @since 1.7
- */
-
-public enum ExtendedCopyOption implements CopyOption {
-    /**
-     * The copy may be interrupted by the {@link Thread#interrupt interrupt}
-     * method.
-     */
-    INTERRUPTIBLE,
-}
--- a/jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedOpenOption.java	Mon May 30 15:28:48 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.nio.file;
-
-import java.nio.file.OpenOption;
-
-/**
- * Defines <em>extended</em> open options supported on some platforms
- * by Sun's provider implementation.
- *
- * @since 1.7
- */
-
-public enum ExtendedOpenOption implements OpenOption {
-    /**
-     * Prevent operations on the file that request read access.
-     */
-    NOSHARE_READ,
-    /**
-     * Prevent operations on the file that request write access.
-     */
-    NOSHARE_WRITE,
-    /**
-     * Prevent operations on the file that request delete access.
-     */
-    NOSHARE_DELETE;
-}
--- a/jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java	Mon May 30 15:28:48 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.nio.file;
-
-import java.nio.file.WatchEvent.Modifier;
-
-/**
- * Defines <em>extended</em> watch event modifiers supported on some platforms
- * by Sun's provider implementation.
- *
- * @since 1.7
- */
-
-public enum ExtendedWatchEventModifier implements Modifier {
-
-    /**
-     * Register a file tree instead of a single directory.
-     */
-    FILE_TREE,
-}
--- a/jdk/src/java.base/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java	Mon May 30 15:28:48 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.nio.file;
-
-import java.nio.file.WatchEvent.Modifier;
-
-/**
- * Defines the <em>sensitivity levels</em> when registering objects with a
- * watch service implementation that polls the file system.
- *
- * @since 1.7
- */
-
-public enum SensitivityWatchEventModifier implements Modifier {
-    /**
-     * High sensitivity.
-     */
-    HIGH(2),
-    /**
-     * Medium sensitivity.
-     */
-    MEDIUM(10),
-    /**
-     * Low sensitivity.
-     */
-    LOW(30);
-
-    /**
-     * Returns the sensitivity in seconds.
-     */
-    public int sensitivityValueInSeconds() {
-        return sensitivity;
-    }
-
-    private final int sensitivity;
-    private SensitivityWatchEventModifier(int sensitivity) {
-        this.sensitivity = sensitivity;
-    }
-}
--- a/jdk/src/java.base/share/classes/module-info.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/java.base/share/classes/module-info.java	Mon May 30 17:38:05 2016 +0100
@@ -216,6 +216,8 @@
     exports sun.nio.cs to
         java.desktop,
         jdk.charsets;
+    exports sun.nio.fs to
+        jdk.unsupported;
     exports sun.reflect.annotation to
         jdk.compiler;
     exports sun.reflect.generics.reflectiveObjects to
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/sun/nio/fs/ExtendedOptions.java	Mon May 30 17:38:05 2016 +0100
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.nio.fs;
+
+import java.nio.file.CopyOption;
+import java.nio.file.OpenOption;
+import java.nio.file.WatchEvent;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Provides support for handling JDK-specific OpenOption, CopyOption and
+ * WatchEvent.Modifier types.
+ */
+
+public final class ExtendedOptions {
+
+    // maps InternalOption to ExternalOption
+    private static final Map<InternalOption<?>, Wrapper<?>> internalToExternal
+        = new ConcurrentHashMap<>();
+
+    /**
+     * Wraps an option or modifier.
+     */
+    private static final class Wrapper<T> {
+        private final Object option;
+        private final T param;
+
+        Wrapper(Object option, T param) {
+            this.option = option;
+            this.param = param;
+        }
+
+        T parameter() {
+            return param;
+        }
+    }
+
+    /**
+     * The internal version of a JDK-specific OpenOption, CopyOption or
+     * WatchEvent.Modifier.
+     */
+    public static final class InternalOption<T> {
+
+        InternalOption() { }
+
+        private void registerInternal(Object option, T param) {
+            Wrapper<T> wrapper = new Wrapper<T>(option, param);
+            internalToExternal.put(this, wrapper);
+        }
+
+        /**
+         * Register this internal option as a OpenOption.
+         */
+        public void register(OpenOption option) {
+            registerInternal(option, null);
+        }
+
+        /**
+         * Register this internal option as a CopyOption.
+         */
+        public void register(CopyOption option) {
+            registerInternal(option, null);
+        }
+
+        /**
+         * Register this internal option as a WatchEvent.Modifier.
+         */
+        public void register(WatchEvent.Modifier option) {
+            registerInternal(option, null);
+        }
+
+        /**
+         * Register this internal option as a WatchEvent.Modifier with the
+         * given parameter.
+         */
+        public void register(WatchEvent.Modifier option, T param) {
+            registerInternal(option, param);
+        }
+
+        /**
+         * Returns true if the given option (or modifier) maps to this internal
+         * option.
+         */
+        public boolean matches(Object option) {
+            Wrapper <?> wrapper = internalToExternal.get(this);
+            if (wrapper == null)
+                return false;
+            else
+                return option == wrapper.option;
+        }
+
+        /**
+         * Returns the parameter object associated with this internal option.
+         */
+        @SuppressWarnings("unchecked")
+        public T parameter() {
+            Wrapper<?> wrapper = internalToExternal.get(this);
+            if (wrapper == null)
+                return null;
+            else
+                return (T) wrapper.parameter();
+        }
+    }
+
+    // Internal equivalents of the options and modifiers defined in
+    // package com.sun.nio.file
+
+    public static final InternalOption<Void> INTERRUPTIBLE = new InternalOption<>();
+
+    public static final InternalOption<Void> NOSHARE_READ = new InternalOption<>();
+    public static final InternalOption<Void> NOSHARE_WRITE = new InternalOption<>();
+    public static final InternalOption<Void> NOSHARE_DELETE = new InternalOption<>();
+
+    public static final InternalOption<Void> FILE_TREE = new InternalOption<>();
+
+    public static final InternalOption<Integer> SENSITIVITY_HIGH = new InternalOption<>();
+    public static final InternalOption<Integer> SENSITIVITY_MEDIUM = new InternalOption<>();
+    public static final InternalOption<Integer> SENSITIVITY_LOW = new InternalOption<>();
+}
--- a/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -25,16 +25,32 @@
 
 package sun.nio.fs;
 
-import java.nio.file.*;
-import java.nio.file.attribute.*;
+import java.nio.file.ClosedWatchServiceException;
+import java.nio.file.DirectoryIteratorException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.NotDirectoryException;
+import java.nio.file.Path;
+import java.nio.file.StandardWatchEventKinds;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchKey;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
 import java.security.PrivilegedActionException;
 import java.io.IOException;
-import java.util.*;
-import java.util.concurrent.*;
-import com.sun.nio.file.SensitivityWatchEventModifier;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Simple WatchService implementation that uses periodic tasks to poll
@@ -46,8 +62,7 @@
     extends AbstractWatchService
 {
     // map of registrations
-    private final Map<Object,PollingWatchKey> map =
-        new HashMap<Object,PollingWatchKey>();
+    private final Map<Object, PollingWatchKey> map = new HashMap<>();
 
     // used to execute the periodic tasks that poll for changes
     private final ScheduledExecutorService scheduledExecutor;
@@ -58,7 +73,7 @@
             .newSingleThreadScheduledExecutor(new ThreadFactory() {
                  @Override
                  public Thread newThread(Runnable r) {
-                     Thread t = new Thread(null, r, "FileSystemWatchService", 0, false);
+                     Thread t = new Thread(null, r, "FileSystemWatcher", 0, false);
                      t.setDaemon(true);
                      return t;
                  }});
@@ -74,8 +89,7 @@
          throws IOException
     {
         // check events - CCE will be thrown if there are invalid elements
-        final Set<WatchEvent.Kind<?>> eventSet =
-            new HashSet<WatchEvent.Kind<?>>(events.length);
+        final Set<WatchEvent.Kind<?>> eventSet = new HashSet<>(events.length);
         for (WatchEvent.Kind<?> event: events) {
             // standard events
             if (event == StandardWatchEventKinds.ENTRY_CREATE ||
@@ -99,17 +113,22 @@
         if (eventSet.isEmpty())
             throw new IllegalArgumentException("No events to register");
 
-        // A modifier may be used to specify the sensitivity level
-        SensitivityWatchEventModifier sensivity = SensitivityWatchEventModifier.MEDIUM;
+        // Extended modifiers may be used to specify the sensitivity level
+        int sensitivity = 10;
         if (modifiers.length > 0) {
             for (WatchEvent.Modifier modifier: modifiers) {
                 if (modifier == null)
                     throw new NullPointerException();
-                if (modifier instanceof SensitivityWatchEventModifier) {
-                    sensivity = (SensitivityWatchEventModifier)modifier;
-                    continue;
+
+                if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) {
+                    sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter();
+                } else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) {
+                    sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter();
+                } else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
+                    sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter();
+                } else {
+                    throw new UnsupportedOperationException("Modifier not supported");
                 }
-                throw new UnsupportedOperationException("Modifier not supported");
             }
         }
 
@@ -120,12 +139,12 @@
         // registration is done in privileged block as it requires the
         // attributes of the entries in the directory.
         try {
-            final SensitivityWatchEventModifier s = sensivity;
+            int value = sensitivity;
             return AccessController.doPrivileged(
                 new PrivilegedExceptionAction<PollingWatchKey>() {
                     @Override
                     public PollingWatchKey run() throws IOException {
-                        return doPrivilegedRegister(path, eventSet, s);
+                        return doPrivilegedRegister(path, eventSet, value);
                     }
                 });
         } catch (PrivilegedActionException pae) {
@@ -140,7 +159,7 @@
     // existing key if already registered
     private PollingWatchKey doPrivilegedRegister(Path path,
                                                  Set<? extends WatchEvent.Kind<?>> events,
-                                                 SensitivityWatchEventModifier sensivity)
+                                                 int sensitivityInSeconds)
         throws IOException
     {
         // check file is a directory and get its file key if possible
@@ -169,7 +188,7 @@
                     watchKey.disable();
                 }
             }
-            watchKey.enable(events, sensivity.sensitivityValueInSeconds());
+            watchKey.enable(events, sensitivityInSeconds);
             return watchKey;
         }
 
@@ -178,7 +197,7 @@
     @Override
     void implClose() throws IOException {
         synchronized (map) {
-            for (Map.Entry<Object,PollingWatchKey> entry: map.entrySet()) {
+            for (Map.Entry<Object, PollingWatchKey> entry: map.entrySet()) {
                 PollingWatchKey watchKey = entry.getValue();
                 watchKey.disable();
                 watchKey.invalidate();
--- a/jdk/src/java.base/solaris/classes/sun/nio/fs/SolarisWatchService.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/java.base/solaris/classes/sun/nio/fs/SolarisWatchService.java	Mon May 30 17:38:05 2016 +0100
@@ -272,9 +272,11 @@
                 for (WatchEvent.Modifier modifier: modifiers) {
                     if (modifier == null)
                         return new NullPointerException();
-                    if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier)
-                        continue; // ignore
-                    return new UnsupportedOperationException("Modifier not supported");
+                    if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
+                            !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
+                            !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
+                        return new UnsupportedOperationException("Modifier not supported");
+                    }
                 }
             }
 
--- a/jdk/src/java.base/unix/classes/sun/nio/fs/UnixCopyFile.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/java.base/unix/classes/sun/nio/fs/UnixCopyFile.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -25,13 +25,18 @@
 
 package sun.nio.fs;
 
-import java.nio.file.*;
 import java.io.IOException;
+import java.nio.file.AtomicMoveNotSupportedException;
+import java.nio.file.CopyOption;
+import java.nio.file.DirectoryNotEmptyException;
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.LinkOption;
+import java.nio.file.LinkPermission;
+import java.nio.file.StandardCopyOption;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
-import com.sun.nio.file.ExtendedCopyOption;
 
 import static sun.nio.fs.UnixNativeDispatcher.*;
 import static sun.nio.fs.UnixConstants.*;
@@ -82,7 +87,7 @@
                     flags.failIfUnableToCopyBasic = true;
                     continue;
                 }
-                if (option == ExtendedCopyOption.INTERRUPTIBLE) {
+                if (ExtendedOptions.INTERRUPTIBLE.matches(option)) {
                     flags.interruptible = true;
                     continue;
                 }
--- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsChannelFactory.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsChannelFactory.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -34,8 +34,6 @@
 import java.nio.file.StandardOpenOption;
 import java.util.Set;
 
-import com.sun.nio.file.ExtendedOpenOption;
-
 import jdk.internal.misc.JavaIOFileDescriptorAccess;
 import jdk.internal.misc.SharedSecrets;
 import sun.nio.ch.FileChannelImpl;
@@ -103,15 +101,6 @@
                     }
                     continue;
                 }
-                if (option instanceof ExtendedOpenOption) {
-                    switch ((ExtendedOpenOption)option) {
-                        case NOSHARE_READ : flags.shareRead = false; break;
-                        case NOSHARE_WRITE : flags.shareWrite = false; break;
-                        case NOSHARE_DELETE : flags.shareDelete = false; break;
-                        default: throw new UnsupportedOperationException();
-                    }
-                    continue;
-                }
                 if (option == LinkOption.NOFOLLOW_LINKS) {
                     flags.noFollowLinks = true;
                     continue;
@@ -120,6 +109,18 @@
                     flags.openReparsePoint = true;
                     continue;
                 }
+                if (ExtendedOptions.NOSHARE_READ.matches(option)) {
+                    flags.shareRead = false;
+                    continue;
+                }
+                if (ExtendedOptions.NOSHARE_WRITE.matches(option)) {
+                    flags.shareWrite = false;
+                    continue;
+                }
+                if (ExtendedOptions.NOSHARE_DELETE.matches(option)) {
+                    flags.shareDelete = false;
+                    continue;
+                }
                 if (option == null)
                     throw new NullPointerException();
                 throw new UnsupportedOperationException();
--- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileCopy.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileCopy.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -28,7 +28,6 @@
 import java.nio.file.*;
 import java.io.IOException;
 import java.util.concurrent.ExecutionException;
-import com.sun.nio.file.ExtendedCopyOption;
 
 import static sun.nio.fs.WindowsNativeDispatcher.*;
 import static sun.nio.fs.WindowsConstants.*;
@@ -67,7 +66,7 @@
                 copyAttributes = true;
                 continue;
             }
-            if (option == ExtendedCopyOption.INTERRUPTIBLE) {
+            if (ExtendedOptions.INTERRUPTIBLE.matches(option)) {
                 interruptible = true;
                 continue;
             }
--- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -32,8 +32,6 @@
 import java.util.*;
 import java.lang.ref.WeakReference;
 
-import com.sun.nio.file.ExtendedWatchEventModifier;
-
 import static sun.nio.fs.WindowsNativeDispatcher.*;
 import static sun.nio.fs.WindowsConstants.*;
 
@@ -864,7 +862,7 @@
                 modifiers = Arrays.copyOf(modifiers, ml);
                 int i=0;
                 while (i < ml) {
-                    if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) {
+                    if (ExtendedOptions.FILE_TREE.matches(modifiers[i++])) {
                         watchSubtree = true;
                         break;
                     }
--- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsWatchService.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsWatchService.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -35,7 +35,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import com.sun.nio.file.ExtendedWatchEventModifier;
 import jdk.internal.misc.Unsafe;
 
 import static sun.nio.fs.WindowsNativeDispatcher.*;
@@ -342,14 +341,16 @@
 
             // FILE_TREE modifier allowed
             for (WatchEvent.Modifier modifier: modifiers) {
-                if (modifier == ExtendedWatchEventModifier.FILE_TREE) {
+                if (ExtendedOptions.FILE_TREE.matches(modifier)) {
                     watchSubtree = true;
                 } else {
                     if (modifier == null)
                         return new NullPointerException();
-                    if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier)
-                        continue; // ignore
-                    return new UnsupportedOperationException("Modifier not supported");
+                    if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
+                            !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
+                            !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
+                        return new UnsupportedOperationException("Modifier not supported");
+                    }
                 }
             }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedCopyOption.java	Mon May 30 17:38:05 2016 +0100
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.nio.file;
+
+import java.nio.file.CopyOption;
+import sun.nio.fs.ExtendedOptions;
+
+/**
+ * Defines <em>extended</em> copy options supported on some platforms
+ * by Sun's provider implementation.
+ *
+ * @since 1.7
+ */
+
+public enum ExtendedCopyOption implements CopyOption {
+    /**
+     * The copy may be interrupted by the {@link Thread#interrupt interrupt}
+     * method.
+     */
+    INTERRUPTIBLE(ExtendedOptions.INTERRUPTIBLE);
+
+    ExtendedCopyOption(ExtendedOptions.InternalOption<Void> option) {
+        option.register(this);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedOpenOption.java	Mon May 30 17:38:05 2016 +0100
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.nio.file;
+
+import java.nio.file.OpenOption;
+import sun.nio.fs.ExtendedOptions;
+
+/**
+ * Defines <em>extended</em> open options supported on some platforms
+ * by Sun's provider implementation.
+ *
+ * @since 1.7
+ */
+
+public enum ExtendedOpenOption implements OpenOption {
+    /**
+     * Prevent operations on the file that request read access.
+     */
+    NOSHARE_READ(ExtendedOptions.NOSHARE_READ),
+    /**
+     * Prevent operations on the file that request write access.
+     */
+    NOSHARE_WRITE(ExtendedOptions.NOSHARE_WRITE),
+    /**
+     * Prevent operations on the file that request delete access.
+     */
+    NOSHARE_DELETE(ExtendedOptions.NOSHARE_DELETE);
+
+    ExtendedOpenOption(ExtendedOptions.InternalOption<Void> option) {
+        option.register(this);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java	Mon May 30 17:38:05 2016 +0100
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.nio.file;
+
+import java.nio.file.WatchEvent.Modifier;
+import sun.nio.fs.ExtendedOptions;
+
+/**
+ * Defines <em>extended</em> watch event modifiers supported on some platforms
+ * by Sun's provider implementation.
+ *
+ * @since 1.7
+ */
+
+public enum ExtendedWatchEventModifier implements Modifier {
+
+    /**
+     * Register a file tree instead of a single directory.
+     */
+    FILE_TREE(ExtendedOptions.FILE_TREE);
+
+    ExtendedWatchEventModifier(ExtendedOptions.InternalOption<Void> option) {
+        option.register(this);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java	Mon May 30 17:38:05 2016 +0100
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.nio.file;
+
+import java.nio.file.WatchEvent.Modifier;
+import sun.nio.fs.ExtendedOptions;
+
+/**
+ * Defines the <em>sensitivity levels</em> when registering objects with a
+ * watch service implementation that polls the file system.
+ *
+ * @since 1.7
+ */
+
+public enum SensitivityWatchEventModifier implements Modifier {
+    /**
+     * High sensitivity.
+     */
+    HIGH(ExtendedOptions.SENSITIVITY_HIGH, 2),
+    /**
+     * Medium sensitivity.
+     */
+    MEDIUM(ExtendedOptions.SENSITIVITY_MEDIUM, 10),
+    /**
+     * Low sensitivity.
+     */
+    LOW(ExtendedOptions.SENSITIVITY_LOW, 30);
+
+    /**
+     * Returns the sensitivity in seconds.
+     */
+    public int sensitivityValueInSeconds() {
+        return sensitivity;
+    }
+
+    private final int sensitivity;
+    private SensitivityWatchEventModifier(ExtendedOptions.InternalOption<Integer> option,
+                                          int sensitivity) {
+        this.sensitivity = sensitivity;
+        option.register(this, sensitivity);
+    }
+}
--- a/jdk/src/jdk.unsupported/share/classes/module-info.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/src/jdk.unsupported/share/classes/module-info.java	Mon May 30 17:38:05 2016 +0100
@@ -26,5 +26,6 @@
 module jdk.unsupported {
     exports sun.misc;
     exports sun.reflect;
+    exports com.sun.nio.file;
 }
 
--- a/jdk/test/java/nio/file/Files/InterruptCopy.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/test/java/nio/file/Files/InterruptCopy.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -24,7 +24,7 @@
 /* @test
  * @bug 4313887 6993267
  * @summary Unit test for Sun-specific ExtendedCopyOption.INTERRUPTIBLE option
- * @modules java.base/com.sun.nio.file
+ * @modules jdk.unsupported
  * @library ..
  */
 
--- a/jdk/test/java/nio/file/Files/SBC.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/test/java/nio/file/Files/SBC.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -25,7 +25,7 @@
  * @bug 4313887
  * @summary Unit test for java.nio.file.Files.newByteChannel
  * @library ..
- * @modules java.base/com.sun.nio.file
+ * @modules jdk.unsupported
  */
 
 import java.nio.ByteBuffer;
--- a/jdk/test/java/nio/file/WatchService/FileTreeModifier.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/test/java/nio/file/WatchService/FileTreeModifier.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -23,9 +23,9 @@
 
 /* @test
  * @bug 4313887 6838333
- * @summary Sanity test for Sun-specific FILE_TREE watch event modifier
+ * @summary Sanity test for JDK-specific FILE_TREE watch event modifier
  * @library ..
- * @modules java.base/com.sun.nio.file
+ * @modules jdk.unsupported
  */
 
 import java.nio.file.*;
--- a/jdk/test/java/nio/file/WatchService/SensitivityModifier.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/test/java/nio/file/WatchService/SensitivityModifier.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -23,8 +23,8 @@
 
 /* @test
  * @bug 4313887
- * @summary Sanity test for Sun-specific sensitivity level watch event modifier
- * @modules java.base/com.sun.nio.file
+ * @summary Sanity test for JDK-specific sensitivity level watch event modifier
+ * @modules jdk.unsupported
  * @library ..
  * @run main/timeout=240 SensitivityModifier
  * @key randomness
--- a/jdk/test/java/nio/file/WatchService/WithSecurityManager.java	Mon May 30 15:28:48 2016 +0900
+++ b/jdk/test/java/nio/file/WatchService/WithSecurityManager.java	Mon May 30 17:38:05 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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
@@ -24,7 +24,7 @@
 /* @test
  * @bug 4313887
  * @summary Unit test for Watchable#register's permission checks
- * @modules java.base/com.sun.nio.file
+ * @modules jdk.unsupported
  * @build WithSecurityManager
  * @run main/othervm WithSecurityManager denyAll.policy - fail
  * @run main/othervm WithSecurityManager denyAll.policy tree fail