// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.File;
import java.io.FilePermission;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedAction;

public class Test5 implements Test {
    public void test() {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            public Void run() {
                System.out.printf("Current dir has %d files\n", new File(".").list().length);
                return null;
            }
        });
    }
    public static void main(String[] args) {
        System.setSecurityManager(new SecurityManager());
        Test5 me = new Test5();
        me.test();
        Test o = null;
        try {
            URLClassLoader cl = new URLClassLoader(new URL[] { new URL("http://localhost/test5x.jar") });
            o = (Test)Class.forName("Test5X", true, cl).getConstructor(Test.class).newInstance(me);
        } catch(Exception ex) {
            System.err.println(ex.getClass().getName() + " : " + ex.getMessage());
            System.exit(1);
        }
        try {
            o.test();
        } catch(AccessControlException ex) {
            System.out.println("Test5X caugth with the hand in the cookie jar: " + ex.getMessage());
        }
    }
}
