Пример #1
0
 static void load() {
   synchronized (Util.class) {
     if (loaded) return;
     loaded = true;
     java.security.AccessController.doPrivileged(new sun.security.action.LoadLibraryAction("net"));
     java.security.AccessController.doPrivileged(new sun.security.action.LoadLibraryAction("nio"));
     // IOUtil must be initialized; Its native methods are called from
     // other places in native nio code so they must be set up.
     IOUtil.initIDs();
   }
 }
Пример #2
0
  /** Utility routine for setting the context class loader. Returns previous class loader. */
  public static ClassLoader setContextClassLoader(ClassLoader newClassLoader) {

    // Can only reference final local variables from dopriveleged block
    final ClassLoader classLoaderToSet = newClassLoader;

    final Thread currentThread = Thread.currentThread();
    ClassLoader originalClassLoader = currentThread.getContextClassLoader();

    if (classLoaderToSet != originalClassLoader) {
      if (System.getSecurityManager() == null) {
        currentThread.setContextClassLoader(classLoaderToSet);
      } else {
        java.security.AccessController.doPrivileged(
            new java.security.PrivilegedAction() {
              public java.lang.Object run() {
                currentThread.setContextClassLoader(classLoaderToSet);
                return null;
              }
            });
      }
    }
    return originalClassLoader;
  }
Пример #3
0
 /**
  * Returns the max size allowed for a cached temp buffers, in bytes. It defaults to
  * Long.MAX_VALUE. It can be set with the jdk.nio.maxCachedBufferSize property. Even though
  * ByteBuffer.capacity() returns an int, we're using a long here for potential future-proofing.
  */
 private static long getMaxCachedBufferSize() {
   String s =
       java.security.AccessController.doPrivileged(
           new PrivilegedAction<String>() {
             @Override
             public String run() {
               return System.getProperty("jdk.nio.maxCachedBufferSize");
             }
           });
   if (s != null) {
     try {
       long m = Long.parseLong(s);
       if (m >= 0) {
         return m;
       } else {
         // if it's negative, ignore the system property
       }
     } catch (NumberFormatException e) {
       // if the string is not well formed, ignore the system property
     }
   }
   return Long.MAX_VALUE;
 }