Exemplo n.º 1
0
 static {
   try {
     newLine =
         (String)
             java.security.AccessController.doPrivileged(
                 new sun.security.action.GetPropertyAction("line.separator"));
   } catch (Throwable t) {
     // print an error
     // LogStdStreams initialized in the main application will redirect this to a file.
     System.err.println(
         "Error getting system line separator for Logging will use \\n\n" + t.toString());
   }
 }
Exemplo n.º 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;
  }