提交 07cf865d 编写于 作者: A alanb

7197637: (ch) sun.nio.ch.Default* cause providers for other platforms to be included in rt.jar

Reviewed-by: mchung
上级 16402350
...@@ -40,6 +40,22 @@ public class DefaultAsynchronousChannelProvider { ...@@ -40,6 +40,22 @@ public class DefaultAsynchronousChannelProvider {
*/ */
private 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. * Returns the default AsynchronousChannelProvider.
*/ */
...@@ -47,12 +63,11 @@ public class DefaultAsynchronousChannelProvider { ...@@ -47,12 +63,11 @@ public class DefaultAsynchronousChannelProvider {
String osname = AccessController String osname = AccessController
.doPrivileged(new GetPropertyAction("os.name")); .doPrivileged(new GetPropertyAction("os.name"));
if (osname.equals("SunOS")) if (osname.equals("SunOS"))
return new SolarisAsynchronousChannelProvider(); return createProvider("sun.nio.ch.SolarisAsynchronousChannelProvider");
if (osname.equals("Linux")) if (osname.equals("Linux"))
return new LinuxAsynchronousChannelProvider(); return createProvider("sun.nio.ch.LinuxAsynchronousChannelProvider");
if (osname.contains("OS X")) if (osname.contains("OS X"))
return new BsdAsynchronousChannelProvider(); return createProvider("sun.nio.ch.BsdAsynchronousChannelProvider");
throw new InternalError("platform not recognized"); throw new InternalError("platform not recognized");
} }
} }
...@@ -27,7 +27,6 @@ package sun.nio.ch; ...@@ -27,7 +27,6 @@ package sun.nio.ch;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
/** /**
...@@ -41,34 +40,32 @@ public class DefaultSelectorProvider { ...@@ -41,34 +40,32 @@ public class DefaultSelectorProvider {
*/ */
private 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. * Returns the default SelectorProvider.
*/ */
public static SelectorProvider create() { public static SelectorProvider create() {
String osname = AccessController.doPrivileged( String osname = AccessController
new GetPropertyAction("os.name")); .doPrivileged(new GetPropertyAction("os.name"));
if ("SunOS".equals(osname)) { if (osname.equals("SunOS"))
return new sun.nio.ch.DevPollSelectorProvider(); return createProvider("sun.nio.ch.DevPollSelectorProvider");
} if (osname.equals("Linux"))
return createProvider("sun.nio.ch.EPollSelectorProvider");
// 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
}
}
}
return new sun.nio.ch.PollSelectorProvider(); return new sun.nio.ch.PollSelectorProvider();
} }
......
...@@ -27,7 +27,6 @@ package sun.nio.fs; ...@@ -27,7 +27,6 @@ package sun.nio.fs;
import java.nio.file.spi.FileSystemProvider; import java.nio.file.spi.FileSystemProvider;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
/** /**
...@@ -38,24 +37,18 @@ public class DefaultFileSystemProvider { ...@@ -38,24 +37,18 @@ public class DefaultFileSystemProvider {
private DefaultFileSystemProvider() { } private DefaultFileSystemProvider() { }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static FileSystemProvider createProvider(final String cn) { private static FileSystemProvider createProvider(String cn) {
return AccessController Class<FileSystemProvider> c;
.doPrivileged(new PrivilegedAction<FileSystemProvider>() { try {
public FileSystemProvider run() { c = (Class<FileSystemProvider>)Class.forName(cn);
Class<FileSystemProvider> c; } catch (ClassNotFoundException x) {
try { throw new AssertionError(x);
c = (Class<FileSystemProvider>)Class.forName(cn, true, null); }
} catch (ClassNotFoundException x) { try {
throw new AssertionError(x); return c.newInstance();
} } catch (IllegalAccessException | InstantiationException x) {
try { throw new AssertionError(x);
return c.newInstance(); }
} catch (IllegalAccessException x) {
throw new AssertionError(x);
} catch (InstantiationException x) {
throw new AssertionError(x);
}
}});
} }
/** /**
...@@ -68,7 +61,7 @@ public class DefaultFileSystemProvider { ...@@ -68,7 +61,7 @@ public class DefaultFileSystemProvider {
return createProvider("sun.nio.fs.SolarisFileSystemProvider"); return createProvider("sun.nio.fs.SolarisFileSystemProvider");
if (osname.equals("Linux")) if (osname.equals("Linux"))
return createProvider("sun.nio.fs.LinuxFileSystemProvider"); 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"); return createProvider("sun.nio.fs.MacOSXFileSystemProvider");
throw new AssertionError("Platform not recognized"); throw new AssertionError("Platform not recognized");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册