home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / io / File.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  5.1 KB  |  275 lines

  1. package java.io;
  2.  
  3. import java.util.Vector;
  4.  
  5. public class File implements Serializable {
  6.    private String path;
  7.    public static final String separator = System.getProperty("file.separator");
  8.    public static final char separatorChar;
  9.    public static final String pathSeparator;
  10.    public static final char pathSeparatorChar;
  11.    private static final long serialVersionUID = 301077366599181567L;
  12.  
  13.    public File(String var1) {
  14.       if (var1 == null) {
  15.          throw new NullPointerException();
  16.       } else {
  17.          this.path = var1;
  18.       }
  19.    }
  20.  
  21.    public File(String var1, String var2) {
  22.       if (var2 == null) {
  23.          throw new NullPointerException();
  24.       } else if (var1 != null) {
  25.          if (var1.endsWith(separator)) {
  26.             this.path = var1 + var2;
  27.          } else {
  28.             this.path = var1 + separator + var2;
  29.          }
  30.       } else {
  31.          this.path = var2;
  32.       }
  33.    }
  34.  
  35.    public File(File var1, String var2) {
  36.       this(var1.getPath(), var2);
  37.    }
  38.  
  39.    public String getName() {
  40.       int var1 = this.path.lastIndexOf(separatorChar);
  41.       return var1 < 0 ? this.path : this.path.substring(var1 + 1);
  42.    }
  43.  
  44.    public String getPath() {
  45.       return this.path;
  46.    }
  47.  
  48.    public String getAbsolutePath() {
  49.       if (this.isAbsolute()) {
  50.          return this.path;
  51.       } else {
  52.          SecurityManager var1 = System.getSecurityManager();
  53.          if (var1 != null) {
  54.             var1.checkPropertyAccess("user.dir");
  55.          }
  56.  
  57.          return System.getProperty("user.dir") + separator + this.path;
  58.       }
  59.    }
  60.  
  61.    public String getCanonicalPath() throws IOException {
  62.       if (this.isAbsolute()) {
  63.          return this.canonPath(this.path);
  64.       } else {
  65.          SecurityManager var1 = System.getSecurityManager();
  66.          if (var1 != null) {
  67.             var1.checkPropertyAccess("user.dir");
  68.          }
  69.  
  70.          return this.canonPath(System.getProperty("user.dir") + separator + this.path);
  71.       }
  72.    }
  73.  
  74.    public String getParent() {
  75.       int var1 = this.path.lastIndexOf(separatorChar);
  76.       if (var1 < 0) {
  77.          return null;
  78.       } else if (this.isAbsolute() && this.path.indexOf(separatorChar) == var1) {
  79.          return var1 < this.path.length() - 1 ? this.path.substring(0, var1 + 1) : null;
  80.       } else {
  81.          return this.path.substring(0, var1);
  82.       }
  83.    }
  84.  
  85.    private native boolean exists0();
  86.  
  87.    private native boolean canWrite0();
  88.  
  89.    private native boolean canRead0();
  90.  
  91.    private native boolean isFile0();
  92.  
  93.    private native boolean isDirectory0();
  94.  
  95.    private native long lastModified0();
  96.  
  97.    private native long length0();
  98.  
  99.    private native boolean mkdir0();
  100.  
  101.    private native boolean renameTo0(File var1);
  102.  
  103.    private native boolean delete0();
  104.  
  105.    private native boolean rmdir0();
  106.  
  107.    private native String[] list0();
  108.  
  109.    private native String canonPath(String var1) throws IOException;
  110.  
  111.    public boolean exists() {
  112.       SecurityManager var1 = System.getSecurityManager();
  113.       if (var1 != null) {
  114.          var1.checkRead(this.path);
  115.       }
  116.  
  117.       return this.exists0();
  118.    }
  119.  
  120.    public boolean canWrite() {
  121.       SecurityManager var1 = System.getSecurityManager();
  122.       if (var1 != null) {
  123.          var1.checkWrite(this.path);
  124.       }
  125.  
  126.       return this.canWrite0();
  127.    }
  128.  
  129.    public boolean canRead() {
  130.       SecurityManager var1 = System.getSecurityManager();
  131.       if (var1 != null) {
  132.          var1.checkRead(this.path);
  133.       }
  134.  
  135.       return this.canRead0();
  136.    }
  137.  
  138.    public boolean isFile() {
  139.       SecurityManager var1 = System.getSecurityManager();
  140.       if (var1 != null) {
  141.          var1.checkRead(this.path);
  142.       }
  143.  
  144.       return this.isFile0();
  145.    }
  146.  
  147.    public boolean isDirectory() {
  148.       SecurityManager var1 = System.getSecurityManager();
  149.       if (var1 != null) {
  150.          var1.checkRead(this.path);
  151.       }
  152.  
  153.       return this.isDirectory0();
  154.    }
  155.  
  156.    public native boolean isAbsolute();
  157.  
  158.    public long lastModified() {
  159.       SecurityManager var1 = System.getSecurityManager();
  160.       if (var1 != null) {
  161.          var1.checkRead(this.path);
  162.       }
  163.  
  164.       return this.lastModified0();
  165.    }
  166.  
  167.    public long length() {
  168.       SecurityManager var1 = System.getSecurityManager();
  169.       if (var1 != null) {
  170.          var1.checkRead(this.path);
  171.       }
  172.  
  173.       return this.length0();
  174.    }
  175.  
  176.    public boolean mkdir() {
  177.       SecurityManager var1 = System.getSecurityManager();
  178.       if (var1 != null) {
  179.          var1.checkWrite(this.path);
  180.       }
  181.  
  182.       return this.mkdir0();
  183.    }
  184.  
  185.    public boolean renameTo(File var1) {
  186.       SecurityManager var2 = System.getSecurityManager();
  187.       if (var2 != null) {
  188.          var2.checkWrite(this.path);
  189.          var2.checkWrite(var1.path);
  190.       }
  191.  
  192.       return this.renameTo0(var1);
  193.    }
  194.  
  195.    public boolean mkdirs() {
  196.       if (this.exists()) {
  197.          return false;
  198.       } else if (this.mkdir()) {
  199.          return true;
  200.       } else {
  201.          String var1 = this.getParent();
  202.          return var1 != null && (new File(var1)).mkdirs() && this.mkdir();
  203.       }
  204.    }
  205.  
  206.    public String[] list() {
  207.       SecurityManager var1 = System.getSecurityManager();
  208.       if (var1 != null) {
  209.          var1.checkRead(this.path);
  210.       }
  211.  
  212.       return this.list0();
  213.    }
  214.  
  215.    public String[] list(FilenameFilter var1) {
  216.       String[] var2 = this.list();
  217.       if (var2 == null) {
  218.          return null;
  219.       } else {
  220.          Vector var3 = new Vector();
  221.  
  222.          for(int var4 = 0; var4 < var2.length; ++var4) {
  223.             if (var1 == null || var1.accept(this, var2[var4])) {
  224.                var3.addElement(var2[var4]);
  225.             }
  226.          }
  227.  
  228.          String[] var5 = new String[var3.size()];
  229.          var3.copyInto(var5);
  230.          return var5;
  231.       }
  232.    }
  233.  
  234.    public boolean delete() {
  235.       SecurityManager var1 = System.getSecurityManager();
  236.       if (var1 != null) {
  237.          var1.checkDelete(this.path);
  238.       }
  239.  
  240.       return this.isDirectory() ? this.rmdir0() : this.delete0();
  241.    }
  242.  
  243.    public int hashCode() {
  244.       return this.path.hashCode() ^ 1234321;
  245.    }
  246.  
  247.    public boolean equals(Object var1) {
  248.       return var1 != null && var1 instanceof File ? this.path.equals(((File)var1).path) : false;
  249.    }
  250.  
  251.    public String toString() {
  252.       return this.getPath();
  253.    }
  254.  
  255.    private synchronized void writeObject(ObjectOutputStream var1) throws IOException {
  256.       var1.defaultWriteObject();
  257.       var1.writeChar(separatorChar);
  258.    }
  259.  
  260.    private synchronized void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  261.       var1.defaultReadObject();
  262.       char var2 = var1.readChar();
  263.       if (var2 != separatorChar) {
  264.          this.path = this.path.replace(var2, separatorChar);
  265.       }
  266.  
  267.    }
  268.  
  269.    static {
  270.       separatorChar = separator.charAt(0);
  271.       pathSeparator = System.getProperty("path.separator");
  272.       pathSeparatorChar = pathSeparator.charAt(0);
  273.    }
  274. }
  275.