7197637: (ch) sun.nio.ch.Default* cause providers for other platforms to be included in rt.jar
Reviewed-by: mchung
This commit is contained in:
parent
3505949495
commit
a9eb740a31
@ -40,6 +40,22 @@ public class DefaultAsynchronousChannelProvider {
|
||||
*/
|
||||
private DefaultAsynchronousChannelProvider() { }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static AsynchronousChannelProvider createProvider(String cn) {
|
||||
Class<AsynchronousChannelProvider> c;
|
||||
try {
|
||||
c = (Class<AsynchronousChannelProvider>)Class.forName(cn);
|
||||
} catch (ClassNotFoundException x) {
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
try {
|
||||
return c.newInstance();
|
||||
} catch (IllegalAccessException | InstantiationException x) {
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default AsynchronousChannelProvider.
|
||||
*/
|
||||
@ -47,12 +63,11 @@ public class DefaultAsynchronousChannelProvider {
|
||||
String osname = AccessController
|
||||
.doPrivileged(new GetPropertyAction("os.name"));
|
||||
if (osname.equals("SunOS"))
|
||||
return new SolarisAsynchronousChannelProvider();
|
||||
return createProvider("sun.nio.ch.SolarisAsynchronousChannelProvider");
|
||||
if (osname.equals("Linux"))
|
||||
return new LinuxAsynchronousChannelProvider();
|
||||
return createProvider("sun.nio.ch.LinuxAsynchronousChannelProvider");
|
||||
if (osname.contains("OS X"))
|
||||
return new BsdAsynchronousChannelProvider();
|
||||
return createProvider("sun.nio.ch.BsdAsynchronousChannelProvider");
|
||||
throw new InternalError("platform not recognized");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ package sun.nio.ch;
|
||||
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
@ -41,34 +40,32 @@ public class DefaultSelectorProvider {
|
||||
*/
|
||||
private DefaultSelectorProvider() { }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static SelectorProvider createProvider(String cn) {
|
||||
Class<SelectorProvider> c;
|
||||
try {
|
||||
c = (Class<SelectorProvider>)Class.forName(cn);
|
||||
} catch (ClassNotFoundException x) {
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
try {
|
||||
return c.newInstance();
|
||||
} catch (IllegalAccessException | InstantiationException x) {
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default SelectorProvider.
|
||||
*/
|
||||
public static SelectorProvider create() {
|
||||
String osname = AccessController.doPrivileged(
|
||||
new GetPropertyAction("os.name"));
|
||||
if ("SunOS".equals(osname)) {
|
||||
return new sun.nio.ch.DevPollSelectorProvider();
|
||||
}
|
||||
|
||||
// use EPollSelectorProvider for Linux kernels >= 2.6
|
||||
if ("Linux".equals(osname)) {
|
||||
String osversion = AccessController.doPrivileged(
|
||||
new GetPropertyAction("os.version"));
|
||||
String[] vers = osversion.split("\\.", 0);
|
||||
if (vers.length >= 2) {
|
||||
try {
|
||||
int major = Integer.parseInt(vers[0]);
|
||||
int minor = Integer.parseInt(vers[1]);
|
||||
if (major > 2 || (major == 2 && minor >= 6)) {
|
||||
return new sun.nio.ch.EPollSelectorProvider();
|
||||
}
|
||||
} catch (NumberFormatException x) {
|
||||
// format not recognized
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String osname = AccessController
|
||||
.doPrivileged(new GetPropertyAction("os.name"));
|
||||
if (osname.equals("SunOS"))
|
||||
return createProvider("sun.nio.ch.DevPollSelectorProvider");
|
||||
if (osname.equals("Linux"))
|
||||
return createProvider("sun.nio.ch.EPollSelectorProvider");
|
||||
return new sun.nio.ch.PollSelectorProvider();
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ package sun.nio.fs;
|
||||
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
@ -38,24 +37,18 @@ public class DefaultFileSystemProvider {
|
||||
private DefaultFileSystemProvider() { }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static FileSystemProvider createProvider(final String cn) {
|
||||
return AccessController
|
||||
.doPrivileged(new PrivilegedAction<FileSystemProvider>() {
|
||||
public FileSystemProvider run() {
|
||||
Class<FileSystemProvider> c;
|
||||
try {
|
||||
c = (Class<FileSystemProvider>)Class.forName(cn, true, null);
|
||||
} catch (ClassNotFoundException x) {
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
try {
|
||||
return c.newInstance();
|
||||
} catch (IllegalAccessException x) {
|
||||
throw new AssertionError(x);
|
||||
} catch (InstantiationException x) {
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
}});
|
||||
private static FileSystemProvider createProvider(String cn) {
|
||||
Class<FileSystemProvider> c;
|
||||
try {
|
||||
c = (Class<FileSystemProvider>)Class.forName(cn);
|
||||
} catch (ClassNotFoundException x) {
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
try {
|
||||
return c.newInstance();
|
||||
} catch (IllegalAccessException | InstantiationException x) {
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +61,7 @@ public class DefaultFileSystemProvider {
|
||||
return createProvider("sun.nio.fs.SolarisFileSystemProvider");
|
||||
if (osname.equals("Linux"))
|
||||
return createProvider("sun.nio.fs.LinuxFileSystemProvider");
|
||||
if (osname.equals("Darwin") || osname.contains("OS X"))
|
||||
if (osname.contains("OS X"))
|
||||
return createProvider("sun.nio.fs.MacOSXFileSystemProvider");
|
||||
throw new AssertionError("Platform not recognized");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user