home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / FilePermission.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  4.3 KB  |  189 lines

  1. package java.io;
  2.  
  3. import java.security.AccessController;
  4. import java.security.Permission;
  5. import java.security.PermissionCollection;
  6.  
  7. public final class FilePermission extends Permission implements Serializable {
  8.    private static final int EXECUTE = 1;
  9.    private static final int WRITE = 2;
  10.    private static final int READ = 4;
  11.    private static final int DELETE = 8;
  12.    private static final int ALL = 15;
  13.    private static final int NONE = 0;
  14.    private transient int mask;
  15.    private transient boolean directory;
  16.    private transient boolean recursive;
  17.    private String actions;
  18.    private transient String cpath;
  19.    private static final char RECURSIVE_CHAR = '-';
  20.    private static final char WILD_CHAR = '*';
  21.    private static final long serialVersionUID = 7930732926638008763L;
  22.  
  23.    private void init(int var1) {
  24.       if ((var1 & 15) != var1) {
  25.          throw new IllegalArgumentException("invalid actions mask");
  26.       } else if (var1 == 0) {
  27.          throw new IllegalArgumentException("invalid actions mask");
  28.       } else if ((this.cpath = this.getName()) == null) {
  29.          throw new NullPointerException("name can't be null");
  30.       } else {
  31.          this.mask = var1;
  32.          if (this.cpath.equals("<<ALL FILES>>")) {
  33.             this.directory = true;
  34.             this.recursive = true;
  35.             this.cpath = "";
  36.          } else {
  37.             this.cpath = (String)AccessController.doPrivileged(new 1(this));
  38.             int var2 = this.cpath.length();
  39.             char var3 = var2 > 0 ? this.cpath.charAt(var2 - 1) : 0;
  40.             if (var3 == '-' && this.cpath.charAt(var2 - 2) == File.separatorChar) {
  41.                this.directory = true;
  42.                this.recursive = true;
  43.                --var2;
  44.                this.cpath = this.cpath.substring(0, var2);
  45.             } else if (var3 == '*' && this.cpath.charAt(var2 - 2) == File.separatorChar) {
  46.                this.directory = true;
  47.                --var2;
  48.                this.cpath = this.cpath.substring(0, var2);
  49.             }
  50.  
  51.          }
  52.       }
  53.    }
  54.  
  55.    public FilePermission(String var1, String var2) {
  56.       super(var1);
  57.       this.init(getMask(var2));
  58.    }
  59.  
  60.    FilePermission(String var1, int var2) {
  61.       super(var1);
  62.       this.init(var2);
  63.    }
  64.  
  65.    public boolean implies(Permission var1) {
  66.       if (!(var1 instanceof FilePermission)) {
  67.          return false;
  68.       } else {
  69.          FilePermission var2 = (FilePermission)var1;
  70.          return (this.mask & var2.mask) == var2.mask && this.impliesIgnoreMask(var2);
  71.       }
  72.    }
  73.  
  74.    boolean impliesIgnoreMask(FilePermission var1) {
  75.       if (!this.directory) {
  76.          return var1.directory ? false : this.cpath.equals(var1.cpath);
  77.       } else if (this.recursive) {
  78.          if (var1.directory) {
  79.             return var1.cpath.length() >= this.cpath.length() && var1.cpath.startsWith(this.cpath);
  80.          } else {
  81.             return var1.cpath.length() > this.cpath.length() && var1.cpath.startsWith(this.cpath);
  82.          }
  83.       } else if (var1.directory) {
  84.          return var1.recursive ? false : this.cpath.equals(var1.cpath);
  85.       } else {
  86.          int var2 = var1.cpath.lastIndexOf(File.separatorChar);
  87.          if (var2 == -1) {
  88.             return false;
  89.          } else {
  90.             return this.cpath.length() == var2 + 1 && this.cpath.regionMatches(0, var1.cpath, 0, var2 + 1);
  91.          }
  92.       }
  93.    }
  94.  
  95.    public boolean equals(Object var1) {
  96.       if (var1 == this) {
  97.          return true;
  98.       } else if (!(var1 instanceof FilePermission)) {
  99.          return false;
  100.       } else {
  101.          FilePermission var2 = (FilePermission)var1;
  102.          return this.mask == var2.mask && this.cpath.equals(var2.cpath) && this.directory == var2.directory && this.recursive == var2.recursive;
  103.       }
  104.    }
  105.  
  106.    public int hashCode() {
  107.       return this.cpath.hashCode();
  108.    }
  109.  
  110.    private static int getMask(String param0) {
  111.       // $FF: Couldn't be decompiled
  112.    }
  113.  
  114.    int getMask() {
  115.       return this.mask;
  116.    }
  117.  
  118.    private static String getActions(int var0) {
  119.       StringBuilder var1 = new StringBuilder();
  120.       boolean var2 = false;
  121.       if ((var0 & 4) == 4) {
  122.          var2 = true;
  123.          var1.append("read");
  124.       }
  125.  
  126.       if ((var0 & 2) == 2) {
  127.          if (var2) {
  128.             var1.append(',');
  129.          } else {
  130.             var2 = true;
  131.          }
  132.  
  133.          var1.append("write");
  134.       }
  135.  
  136.       if ((var0 & 1) == 1) {
  137.          if (var2) {
  138.             var1.append(',');
  139.          } else {
  140.             var2 = true;
  141.          }
  142.  
  143.          var1.append("execute");
  144.       }
  145.  
  146.       if ((var0 & 8) == 8) {
  147.          if (var2) {
  148.             var1.append(',');
  149.          } else {
  150.             var2 = true;
  151.          }
  152.  
  153.          var1.append("delete");
  154.       }
  155.  
  156.       return var1.toString();
  157.    }
  158.  
  159.    public String getActions() {
  160.       if (this.actions == null) {
  161.          this.actions = getActions(this.mask);
  162.       }
  163.  
  164.       return this.actions;
  165.    }
  166.  
  167.    public PermissionCollection newPermissionCollection() {
  168.       return new FilePermissionCollection();
  169.    }
  170.  
  171.    private void writeObject(ObjectOutputStream var1) throws IOException {
  172.       if (this.actions == null) {
  173.          this.getActions();
  174.       }
  175.  
  176.       var1.defaultWriteObject();
  177.    }
  178.  
  179.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  180.       var1.defaultReadObject();
  181.       this.init(getMask(this.actions));
  182.    }
  183.  
  184.    // $FF: synthetic method
  185.    static String access$000(FilePermission var0) {
  186.       return var0.cpath;
  187.    }
  188. }
  189.