Code example for SocketPermission

0
        try { 
            SocketPermission p0= new SocketPermission("example.com","connect");
            PermissionCollection pc = p0.newPermissionCollection();
            pc.setReadOnly();   // this should lock out future adds
            // 
            SocketPermission p1= new SocketPermission("example.net","connect");
            pc.add(p1);
            throw new 
                Exception("Failed...SocketPermission added to readonly SocketPermissionCollection.");
 
        } catch (SecurityException se) {
            System.out.println("SocketPermissionCollection passed");
        } 
 
    } 
 
    static void tryFilePC() throws Exception { 
        try { 
            FilePermission p0 = new FilePermission("/home/foobar","read");
            PermissionCollection pc = p0.newPermissionCollection();
            pc.setReadOnly();   // this should lock out future adds