8066258: Re-examine com.sun.nio.file to see if it should be a supported API

Reviewed-by: chegar
This commit is contained in:
Alan Bateman 2016-05-30 17:38:05 +01:00
parent 2f8dcbe90f
commit a5e1465831
20 changed files with 274 additions and 83 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -232,9 +232,11 @@ class LinuxWatchService
for (WatchEvent.Modifier modifier: modifiers) { for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == null) if (modifier == null)
return new NullPointerException(); return new NullPointerException();
if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier) if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
continue; // ignore !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
return new UnsupportedOperationException("Modifier not supported"); !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
return new UnsupportedOperationException("Modifier not supported");
}
} }
} }

View File

@ -216,6 +216,8 @@ module java.base {
exports sun.nio.cs to exports sun.nio.cs to
java.desktop, java.desktop,
jdk.charsets; jdk.charsets;
exports sun.nio.fs to
jdk.unsupported;
exports sun.reflect.annotation to exports sun.reflect.annotation to
jdk.compiler; jdk.compiler;
exports sun.reflect.generics.reflectiveObjects to exports sun.reflect.generics.reflectiveObjects to

View File

@ -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<>();
}

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,16 +25,32 @@
package sun.nio.fs; package sun.nio.fs;
import java.nio.file.*; import java.nio.file.ClosedWatchServiceException;
import java.nio.file.attribute.*; 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.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.HashMap;
import java.util.concurrent.*; import java.util.HashSet;
import com.sun.nio.file.SensitivityWatchEventModifier; 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 * Simple WatchService implementation that uses periodic tasks to poll
@ -46,8 +62,7 @@ class PollingWatchService
extends AbstractWatchService extends AbstractWatchService
{ {
// map of registrations // map of registrations
private final Map<Object,PollingWatchKey> map = private final Map<Object, PollingWatchKey> map = new HashMap<>();
new HashMap<Object,PollingWatchKey>();
// used to execute the periodic tasks that poll for changes // used to execute the periodic tasks that poll for changes
private final ScheduledExecutorService scheduledExecutor; private final ScheduledExecutorService scheduledExecutor;
@ -58,7 +73,7 @@ class PollingWatchService
.newSingleThreadScheduledExecutor(new ThreadFactory() { .newSingleThreadScheduledExecutor(new ThreadFactory() {
@Override @Override
public Thread newThread(Runnable r) { 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); t.setDaemon(true);
return t; return t;
}}); }});
@ -74,8 +89,7 @@ class PollingWatchService
throws IOException throws IOException
{ {
// check events - CCE will be thrown if there are invalid elements // check events - CCE will be thrown if there are invalid elements
final Set<WatchEvent.Kind<?>> eventSet = final Set<WatchEvent.Kind<?>> eventSet = new HashSet<>(events.length);
new HashSet<WatchEvent.Kind<?>>(events.length);
for (WatchEvent.Kind<?> event: events) { for (WatchEvent.Kind<?> event: events) {
// standard events // standard events
if (event == StandardWatchEventKinds.ENTRY_CREATE || if (event == StandardWatchEventKinds.ENTRY_CREATE ||
@ -99,17 +113,22 @@ class PollingWatchService
if (eventSet.isEmpty()) if (eventSet.isEmpty())
throw new IllegalArgumentException("No events to register"); throw new IllegalArgumentException("No events to register");
// A modifier may be used to specify the sensitivity level // Extended modifiers may be used to specify the sensitivity level
SensitivityWatchEventModifier sensivity = SensitivityWatchEventModifier.MEDIUM; int sensitivity = 10;
if (modifiers.length > 0) { if (modifiers.length > 0) {
for (WatchEvent.Modifier modifier: modifiers) { for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == null) if (modifier == null)
throw new NullPointerException(); throw new NullPointerException();
if (modifier instanceof SensitivityWatchEventModifier) {
sensivity = (SensitivityWatchEventModifier)modifier; if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) {
continue; 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 @@ class PollingWatchService
// registration is done in privileged block as it requires the // registration is done in privileged block as it requires the
// attributes of the entries in the directory. // attributes of the entries in the directory.
try { try {
final SensitivityWatchEventModifier s = sensivity; int value = sensitivity;
return AccessController.doPrivileged( return AccessController.doPrivileged(
new PrivilegedExceptionAction<PollingWatchKey>() { new PrivilegedExceptionAction<PollingWatchKey>() {
@Override @Override
public PollingWatchKey run() throws IOException { public PollingWatchKey run() throws IOException {
return doPrivilegedRegister(path, eventSet, s); return doPrivilegedRegister(path, eventSet, value);
} }
}); });
} catch (PrivilegedActionException pae) { } catch (PrivilegedActionException pae) {
@ -140,7 +159,7 @@ class PollingWatchService
// existing key if already registered // existing key if already registered
private PollingWatchKey doPrivilegedRegister(Path path, private PollingWatchKey doPrivilegedRegister(Path path,
Set<? extends WatchEvent.Kind<?>> events, Set<? extends WatchEvent.Kind<?>> events,
SensitivityWatchEventModifier sensivity) int sensitivityInSeconds)
throws IOException throws IOException
{ {
// check file is a directory and get its file key if possible // check file is a directory and get its file key if possible
@ -169,7 +188,7 @@ class PollingWatchService
watchKey.disable(); watchKey.disable();
} }
} }
watchKey.enable(events, sensivity.sensitivityValueInSeconds()); watchKey.enable(events, sensitivityInSeconds);
return watchKey; return watchKey;
} }
@ -178,7 +197,7 @@ class PollingWatchService
@Override @Override
void implClose() throws IOException { void implClose() throws IOException {
synchronized (map) { synchronized (map) {
for (Map.Entry<Object,PollingWatchKey> entry: map.entrySet()) { for (Map.Entry<Object, PollingWatchKey> entry: map.entrySet()) {
PollingWatchKey watchKey = entry.getValue(); PollingWatchKey watchKey = entry.getValue();
watchKey.disable(); watchKey.disable();
watchKey.invalidate(); watchKey.invalidate();

View File

@ -272,9 +272,11 @@ class SolarisWatchService
for (WatchEvent.Modifier modifier: modifiers) { for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == null) if (modifier == null)
return new NullPointerException(); return new NullPointerException();
if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier) if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
continue; // ignore !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
return new UnsupportedOperationException("Modifier not supported"); !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
return new UnsupportedOperationException("Modifier not supported");
}
} }
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,13 +25,18 @@
package sun.nio.fs; package sun.nio.fs;
import java.nio.file.*;
import java.io.IOException; 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.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.sun.nio.file.ExtendedCopyOption;
import static sun.nio.fs.UnixNativeDispatcher.*; import static sun.nio.fs.UnixNativeDispatcher.*;
import static sun.nio.fs.UnixConstants.*; import static sun.nio.fs.UnixConstants.*;
@ -82,7 +87,7 @@ class UnixCopyFile {
flags.failIfUnableToCopyBasic = true; flags.failIfUnableToCopyBasic = true;
continue; continue;
} }
if (option == ExtendedCopyOption.INTERRUPTIBLE) { if (ExtendedOptions.INTERRUPTIBLE.matches(option)) {
flags.interruptible = true; flags.interruptible = true;
continue; continue;
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,8 +34,6 @@ import java.nio.file.OpenOption;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.Set; import java.util.Set;
import com.sun.nio.file.ExtendedOpenOption;
import jdk.internal.misc.JavaIOFileDescriptorAccess; import jdk.internal.misc.JavaIOFileDescriptorAccess;
import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.SharedSecrets;
import sun.nio.ch.FileChannelImpl; import sun.nio.ch.FileChannelImpl;
@ -103,15 +101,6 @@ class WindowsChannelFactory {
} }
continue; 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) { if (option == LinkOption.NOFOLLOW_LINKS) {
flags.noFollowLinks = true; flags.noFollowLinks = true;
continue; continue;
@ -120,6 +109,18 @@ class WindowsChannelFactory {
flags.openReparsePoint = true; flags.openReparsePoint = true;
continue; 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) if (option == null)
throw new NullPointerException(); throw new NullPointerException();
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,6 @@ package sun.nio.fs;
import java.nio.file.*; import java.nio.file.*;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import com.sun.nio.file.ExtendedCopyOption;
import static sun.nio.fs.WindowsNativeDispatcher.*; import static sun.nio.fs.WindowsNativeDispatcher.*;
import static sun.nio.fs.WindowsConstants.*; import static sun.nio.fs.WindowsConstants.*;
@ -67,7 +66,7 @@ class WindowsFileCopy {
copyAttributes = true; copyAttributes = true;
continue; continue;
} }
if (option == ExtendedCopyOption.INTERRUPTIBLE) { if (ExtendedOptions.INTERRUPTIBLE.matches(option)) {
interruptible = true; interruptible = true;
continue; continue;
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -32,8 +32,6 @@ import java.net.URI;
import java.util.*; import java.util.*;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import com.sun.nio.file.ExtendedWatchEventModifier;
import static sun.nio.fs.WindowsNativeDispatcher.*; import static sun.nio.fs.WindowsNativeDispatcher.*;
import static sun.nio.fs.WindowsConstants.*; import static sun.nio.fs.WindowsConstants.*;
@ -864,7 +862,7 @@ class WindowsPath implements Path {
modifiers = Arrays.copyOf(modifiers, ml); modifiers = Arrays.copyOf(modifiers, ml);
int i=0; int i=0;
while (i < ml) { while (i < ml) {
if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { if (ExtendedOptions.FILE_TREE.matches(modifiers[i++])) {
watchSubtree = true; watchSubtree = true;
break; break;
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -35,7 +35,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.sun.nio.file.ExtendedWatchEventModifier;
import jdk.internal.misc.Unsafe; import jdk.internal.misc.Unsafe;
import static sun.nio.fs.WindowsNativeDispatcher.*; import static sun.nio.fs.WindowsNativeDispatcher.*;
@ -342,14 +341,16 @@ class WindowsWatchService
// FILE_TREE modifier allowed // FILE_TREE modifier allowed
for (WatchEvent.Modifier modifier: modifiers) { for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == ExtendedWatchEventModifier.FILE_TREE) { if (ExtendedOptions.FILE_TREE.matches(modifier)) {
watchSubtree = true; watchSubtree = true;
} else { } else {
if (modifier == null) if (modifier == null)
return new NullPointerException(); return new NullPointerException();
if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier) if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
continue; // ignore !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
return new UnsupportedOperationException("Modifier not supported"); !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
return new UnsupportedOperationException("Modifier not supported");
}
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
package com.sun.nio.file; package com.sun.nio.file;
import java.nio.file.CopyOption; import java.nio.file.CopyOption;
import sun.nio.fs.ExtendedOptions;
/** /**
* Defines <em>extended</em> copy options supported on some platforms * Defines <em>extended</em> copy options supported on some platforms
@ -39,5 +40,9 @@ public enum ExtendedCopyOption implements CopyOption {
* The copy may be interrupted by the {@link Thread#interrupt interrupt} * The copy may be interrupted by the {@link Thread#interrupt interrupt}
* method. * method.
*/ */
INTERRUPTIBLE, INTERRUPTIBLE(ExtendedOptions.INTERRUPTIBLE);
ExtendedCopyOption(ExtendedOptions.InternalOption<Void> option) {
option.register(this);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
package com.sun.nio.file; package com.sun.nio.file;
import java.nio.file.OpenOption; import java.nio.file.OpenOption;
import sun.nio.fs.ExtendedOptions;
/** /**
* Defines <em>extended</em> open options supported on some platforms * Defines <em>extended</em> open options supported on some platforms
@ -38,13 +39,17 @@ public enum ExtendedOpenOption implements OpenOption {
/** /**
* Prevent operations on the file that request read access. * Prevent operations on the file that request read access.
*/ */
NOSHARE_READ, NOSHARE_READ(ExtendedOptions.NOSHARE_READ),
/** /**
* Prevent operations on the file that request write access. * Prevent operations on the file that request write access.
*/ */
NOSHARE_WRITE, NOSHARE_WRITE(ExtendedOptions.NOSHARE_WRITE),
/** /**
* Prevent operations on the file that request delete access. * Prevent operations on the file that request delete access.
*/ */
NOSHARE_DELETE; NOSHARE_DELETE(ExtendedOptions.NOSHARE_DELETE);
ExtendedOpenOption(ExtendedOptions.InternalOption<Void> option) {
option.register(this);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
package com.sun.nio.file; package com.sun.nio.file;
import java.nio.file.WatchEvent.Modifier; import java.nio.file.WatchEvent.Modifier;
import sun.nio.fs.ExtendedOptions;
/** /**
* Defines <em>extended</em> watch event modifiers supported on some platforms * Defines <em>extended</em> watch event modifiers supported on some platforms
@ -39,5 +40,9 @@ public enum ExtendedWatchEventModifier implements Modifier {
/** /**
* Register a file tree instead of a single directory. * Register a file tree instead of a single directory.
*/ */
FILE_TREE, FILE_TREE(ExtendedOptions.FILE_TREE);
ExtendedWatchEventModifier(ExtendedOptions.InternalOption<Void> option) {
option.register(this);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
package com.sun.nio.file; package com.sun.nio.file;
import java.nio.file.WatchEvent.Modifier; import java.nio.file.WatchEvent.Modifier;
import sun.nio.fs.ExtendedOptions;
/** /**
* Defines the <em>sensitivity levels</em> when registering objects with a * Defines the <em>sensitivity levels</em> when registering objects with a
@ -38,15 +39,15 @@ public enum SensitivityWatchEventModifier implements Modifier {
/** /**
* High sensitivity. * High sensitivity.
*/ */
HIGH(2), HIGH(ExtendedOptions.SENSITIVITY_HIGH, 2),
/** /**
* Medium sensitivity. * Medium sensitivity.
*/ */
MEDIUM(10), MEDIUM(ExtendedOptions.SENSITIVITY_MEDIUM, 10),
/** /**
* Low sensitivity. * Low sensitivity.
*/ */
LOW(30); LOW(ExtendedOptions.SENSITIVITY_LOW, 30);
/** /**
* Returns the sensitivity in seconds. * Returns the sensitivity in seconds.
@ -56,7 +57,9 @@ public enum SensitivityWatchEventModifier implements Modifier {
} }
private final int sensitivity; private final int sensitivity;
private SensitivityWatchEventModifier(int sensitivity) { private SensitivityWatchEventModifier(ExtendedOptions.InternalOption<Integer> option,
int sensitivity) {
this.sensitivity = sensitivity; this.sensitivity = sensitivity;
option.register(this, sensitivity);
} }
} }

View File

@ -26,5 +26,6 @@
module jdk.unsupported { module jdk.unsupported {
exports sun.misc; exports sun.misc;
exports sun.reflect; exports sun.reflect;
exports com.sun.nio.file;
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test /* @test
* @bug 4313887 6993267 * @bug 4313887 6993267
* @summary Unit test for Sun-specific ExtendedCopyOption.INTERRUPTIBLE option * @summary Unit test for Sun-specific ExtendedCopyOption.INTERRUPTIBLE option
* @modules java.base/com.sun.nio.file * @modules jdk.unsupported
* @library .. * @library ..
*/ */

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
* @bug 4313887 * @bug 4313887
* @summary Unit test for java.nio.file.Files.newByteChannel * @summary Unit test for java.nio.file.Files.newByteChannel
* @library .. * @library ..
* @modules java.base/com.sun.nio.file * @modules jdk.unsupported
*/ */
import java.nio.ByteBuffer; import java.nio.ByteBuffer;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,9 +23,9 @@
/* @test /* @test
* @bug 4313887 6838333 * @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 .. * @library ..
* @modules java.base/com.sun.nio.file * @modules jdk.unsupported
*/ */
import java.nio.file.*; import java.nio.file.*;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,8 +23,8 @@
/* @test /* @test
* @bug 4313887 * @bug 4313887
* @summary Sanity test for Sun-specific sensitivity level watch event modifier * @summary Sanity test for JDK-specific sensitivity level watch event modifier
* @modules java.base/com.sun.nio.file * @modules jdk.unsupported
* @library .. * @library ..
* @run main/timeout=240 SensitivityModifier * @run main/timeout=240 SensitivityModifier
* @key randomness * @key randomness

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test /* @test
* @bug 4313887 * @bug 4313887
* @summary Unit test for Watchable#register's permission checks * @summary Unit test for Watchable#register's permission checks
* @modules java.base/com.sun.nio.file * @modules jdk.unsupported
* @build WithSecurityManager * @build WithSecurityManager
* @run main/othervm WithSecurityManager denyAll.policy - fail * @run main/othervm WithSecurityManager denyAll.policy - fail
* @run main/othervm WithSecurityManager denyAll.policy tree fail * @run main/othervm WithSecurityManager denyAll.policy tree fail