home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / io / File.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  7.8 KB  |  479 lines

  1. package java.io;
  2.  
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5. import java.security.AccessControlException;
  6. import java.security.AccessController;
  7. import java.util.ArrayList;
  8. import java.util.Random;
  9. import sun.security.action.GetPropertyAction;
  10.  
  11. public class File implements Serializable, Comparable {
  12.    // $FF: renamed from: fs java.io.FileSystem
  13.    private static FileSystem field_0 = FileSystem.getFileSystem();
  14.    private String path;
  15.    private transient int prefixLength;
  16.    public static final char separatorChar;
  17.    public static final String separator;
  18.    public static final char pathSeparatorChar;
  19.    public static final String pathSeparator;
  20.    private static final Object tmpFileLock;
  21.    private static int counter;
  22.    private static String tmpdir;
  23.    private static final long serialVersionUID = 301077366599181567L;
  24.  
  25.    int getPrefixLength() {
  26.       return this.prefixLength;
  27.    }
  28.  
  29.    private File(String var1, int var2) {
  30.       this.path = var1;
  31.       this.prefixLength = var2;
  32.    }
  33.  
  34.    public File(String var1) {
  35.       if (var1 == null) {
  36.          throw new NullPointerException();
  37.       } else {
  38.          this.path = field_0.normalize(var1);
  39.          this.prefixLength = field_0.prefixLength(this.path);
  40.       }
  41.    }
  42.  
  43.    public File(String var1, String var2) {
  44.       if (var2 == null) {
  45.          throw new NullPointerException();
  46.       } else {
  47.          if (var1 != null) {
  48.             if (var1.equals("")) {
  49.                this.path = field_0.resolve(field_0.getDefaultParent(), field_0.normalize(var2));
  50.             } else {
  51.                this.path = field_0.resolve(field_0.normalize(var1), field_0.normalize(var2));
  52.             }
  53.          } else {
  54.             this.path = field_0.normalize(var2);
  55.          }
  56.  
  57.          this.prefixLength = field_0.prefixLength(this.path);
  58.       }
  59.    }
  60.  
  61.    public File(File var1, String var2) {
  62.       if (var2 == null) {
  63.          throw new NullPointerException();
  64.       } else {
  65.          if (var1 != null) {
  66.             if (var1.path.equals("")) {
  67.                this.path = field_0.resolve(field_0.getDefaultParent(), field_0.normalize(var2));
  68.             } else {
  69.                this.path = field_0.resolve(var1.path, field_0.normalize(var2));
  70.             }
  71.          } else {
  72.             this.path = field_0.normalize(var2);
  73.          }
  74.  
  75.          this.prefixLength = field_0.prefixLength(this.path);
  76.       }
  77.    }
  78.  
  79.    public String getName() {
  80.       int var1 = this.path.lastIndexOf(separatorChar);
  81.       return var1 < this.prefixLength ? this.path.substring(this.prefixLength) : this.path.substring(var1 + 1);
  82.    }
  83.  
  84.    public String getParent() {
  85.       int var1 = this.path.lastIndexOf(separatorChar);
  86.       if (var1 < this.prefixLength) {
  87.          return this.prefixLength > 0 && this.path.length() > this.prefixLength ? this.path.substring(0, this.prefixLength) : null;
  88.       } else {
  89.          return this.path.substring(0, var1);
  90.       }
  91.    }
  92.  
  93.    public File getParentFile() {
  94.       String var1 = this.getParent();
  95.       return var1 == null ? null : new File(var1, this.prefixLength);
  96.    }
  97.  
  98.    public String getPath() {
  99.       return this.path;
  100.    }
  101.  
  102.    public boolean isAbsolute() {
  103.       return field_0.isAbsolute(this);
  104.    }
  105.  
  106.    public String getAbsolutePath() {
  107.       return field_0.resolve(this);
  108.    }
  109.  
  110.    public File getAbsoluteFile() {
  111.       return new File(this.getAbsolutePath());
  112.    }
  113.  
  114.    public String getCanonicalPath() throws IOException {
  115.       return field_0.canonicalize(field_0.resolve(this));
  116.    }
  117.  
  118.    public File getCanonicalFile() throws IOException {
  119.       return new File(this.getCanonicalPath());
  120.    }
  121.  
  122.    public URL toURL() throws MalformedURLException {
  123.       String var1 = this.getAbsolutePath();
  124.       if (separatorChar != '/') {
  125.          var1 = var1.replace(separatorChar, '/');
  126.       }
  127.  
  128.       if (!var1.startsWith("/")) {
  129.          var1 = "/" + var1;
  130.       }
  131.  
  132.       if (!var1.endsWith("/") && this.isDirectory()) {
  133.          var1 = var1 + "/";
  134.       }
  135.  
  136.       return new URL("file", "", var1);
  137.    }
  138.  
  139.    public boolean canRead() {
  140.       SecurityManager var1 = System.getSecurityManager();
  141.       if (var1 != null) {
  142.          var1.checkRead(this.path);
  143.       }
  144.  
  145.       return field_0.checkAccess(this, false);
  146.    }
  147.  
  148.    public boolean canWrite() {
  149.       SecurityManager var1 = System.getSecurityManager();
  150.       if (var1 != null) {
  151.          var1.checkWrite(this.path);
  152.       }
  153.  
  154.       return field_0.checkAccess(this, true);
  155.    }
  156.  
  157.    public boolean exists() {
  158.       SecurityManager var1 = System.getSecurityManager();
  159.       if (var1 != null) {
  160.          var1.checkRead(this.path);
  161.       }
  162.  
  163.       return (field_0.getBooleanAttributes(this) & 1) != 0;
  164.    }
  165.  
  166.    public boolean isDirectory() {
  167.       SecurityManager var1 = System.getSecurityManager();
  168.       if (var1 != null) {
  169.          var1.checkRead(this.path);
  170.       }
  171.  
  172.       return (field_0.getBooleanAttributes(this) & 4) != 0;
  173.    }
  174.  
  175.    public boolean isFile() {
  176.       SecurityManager var1 = System.getSecurityManager();
  177.       if (var1 != null) {
  178.          var1.checkRead(this.path);
  179.       }
  180.  
  181.       return (field_0.getBooleanAttributes(this) & 2) != 0;
  182.    }
  183.  
  184.    public boolean isHidden() {
  185.       SecurityManager var1 = System.getSecurityManager();
  186.       if (var1 != null) {
  187.          var1.checkRead(this.path);
  188.       }
  189.  
  190.       return (field_0.getBooleanAttributes(this) & 8) != 0;
  191.    }
  192.  
  193.    public long lastModified() {
  194.       SecurityManager var1 = System.getSecurityManager();
  195.       if (var1 != null) {
  196.          var1.checkRead(this.path);
  197.       }
  198.  
  199.       return field_0.getLastModifiedTime(this);
  200.    }
  201.  
  202.    public long length() {
  203.       SecurityManager var1 = System.getSecurityManager();
  204.       if (var1 != null) {
  205.          var1.checkRead(this.path);
  206.       }
  207.  
  208.       return field_0.getLength(this);
  209.    }
  210.  
  211.    public boolean createNewFile() throws IOException {
  212.       SecurityManager var1 = System.getSecurityManager();
  213.       if (var1 != null) {
  214.          var1.checkWrite(this.path);
  215.       }
  216.  
  217.       return field_0.createFileExclusively(this.path);
  218.    }
  219.  
  220.    public boolean delete() {
  221.       SecurityManager var1 = System.getSecurityManager();
  222.       if (var1 != null) {
  223.          var1.checkDelete(this.path);
  224.       }
  225.  
  226.       return field_0.delete(this);
  227.    }
  228.  
  229.    public void deleteOnExit() {
  230.       SecurityManager var1 = System.getSecurityManager();
  231.       if (var1 != null) {
  232.          var1.checkDelete(this.path);
  233.       }
  234.  
  235.       field_0.deleteOnExit(this);
  236.    }
  237.  
  238.    public String[] list() {
  239.       SecurityManager var1 = System.getSecurityManager();
  240.       if (var1 != null) {
  241.          var1.checkRead(this.path);
  242.       }
  243.  
  244.       return field_0.list(this);
  245.    }
  246.  
  247.    public String[] list(FilenameFilter var1) {
  248.       String[] var2 = this.list();
  249.       if (var2 != null && var1 != null) {
  250.          ArrayList var3 = new ArrayList();
  251.  
  252.          for(int var4 = 0; var4 < var2.length; ++var4) {
  253.             if (var1.accept(this, var2[var4])) {
  254.                var3.add(var2[var4]);
  255.             }
  256.          }
  257.  
  258.          return (String[])var3.toArray(new String[0]);
  259.       } else {
  260.          return var2;
  261.       }
  262.    }
  263.  
  264.    public File[] listFiles() {
  265.       String[] var1 = this.list();
  266.       if (var1 == null) {
  267.          return null;
  268.       } else {
  269.          int var2 = var1.length;
  270.          File[] var3 = new File[var2];
  271.  
  272.          for(int var4 = 0; var4 < var2; ++var4) {
  273.             var3[var4] = new File(this.path, var1[var4]);
  274.          }
  275.  
  276.          return var3;
  277.       }
  278.    }
  279.  
  280.    public File[] listFiles(FilenameFilter var1) {
  281.       String[] var2 = this.list();
  282.       if (var2 == null) {
  283.          return null;
  284.       } else {
  285.          ArrayList var3 = new ArrayList();
  286.  
  287.          for(int var4 = 0; var4 < var2.length; ++var4) {
  288.             if (var1 == null || var1.accept(this, var2[var4])) {
  289.                var3.add(new File(this.path, var2[var4]));
  290.             }
  291.          }
  292.  
  293.          return (File[])var3.toArray(new File[0]);
  294.       }
  295.    }
  296.  
  297.    public File[] listFiles(FileFilter var1) {
  298.       String[] var2 = this.list();
  299.       if (var2 == null) {
  300.          return null;
  301.       } else {
  302.          ArrayList var3 = new ArrayList();
  303.  
  304.          for(int var4 = 0; var4 < var2.length; ++var4) {
  305.             File var5 = new File(this.path, var2[var4]);
  306.             if (var1 == null || var1.accept(var5)) {
  307.                var3.add(var5);
  308.             }
  309.          }
  310.  
  311.          return (File[])var3.toArray(new File[0]);
  312.       }
  313.    }
  314.  
  315.    public boolean mkdir() {
  316.       SecurityManager var1 = System.getSecurityManager();
  317.       if (var1 != null) {
  318.          var1.checkWrite(this.path);
  319.       }
  320.  
  321.       return field_0.createDirectory(this);
  322.    }
  323.  
  324.    public boolean mkdirs() {
  325.       if (this.exists()) {
  326.          return false;
  327.       } else if (this.mkdir()) {
  328.          return true;
  329.       } else {
  330.          String var1 = this.getParent();
  331.          return var1 != null && (new File(var1)).mkdirs() && this.mkdir();
  332.       }
  333.    }
  334.  
  335.    public boolean renameTo(File var1) {
  336.       SecurityManager var2 = System.getSecurityManager();
  337.       if (var2 != null) {
  338.          var2.checkWrite(this.path);
  339.          var2.checkWrite(var1.path);
  340.       }
  341.  
  342.       return field_0.rename(this, var1);
  343.    }
  344.  
  345.    public boolean setLastModified(long var1) {
  346.       if (var1 < 0L) {
  347.          throw new IllegalArgumentException("Negative time");
  348.       } else {
  349.          SecurityManager var3 = System.getSecurityManager();
  350.          if (var3 != null) {
  351.             var3.checkWrite(this.path);
  352.          }
  353.  
  354.          return field_0.setLastModifiedTime(this, var1);
  355.       }
  356.    }
  357.  
  358.    public boolean setReadOnly() {
  359.       SecurityManager var1 = System.getSecurityManager();
  360.       if (var1 != null) {
  361.          var1.checkWrite(this.path);
  362.       }
  363.  
  364.       return field_0.setReadOnly(this);
  365.    }
  366.  
  367.    public static File[] listRoots() {
  368.       return field_0.listRoots();
  369.    }
  370.  
  371.    private static File generateFile(String var0, String var1, File var2) throws IOException {
  372.       if (counter == -1) {
  373.          counter = (new Random()).nextInt() & '\uffff';
  374.       }
  375.  
  376.       ++counter;
  377.       return new File(var2, var0 + Integer.toString(counter) + var1);
  378.    }
  379.  
  380.    private static String getTempDir() {
  381.       if (tmpdir == null) {
  382.          GetPropertyAction var0 = new GetPropertyAction("java.io.tmpdir");
  383.          tmpdir = (String)AccessController.doPrivileged(var0);
  384.       }
  385.  
  386.       return tmpdir;
  387.    }
  388.  
  389.    private static boolean checkAndCreate(String var0, SecurityManager var1) throws IOException {
  390.       if (var1 != null) {
  391.          try {
  392.             var1.checkWrite(var0);
  393.          } catch (AccessControlException var3) {
  394.             throw new SecurityException("Unable to create temporary file");
  395.          }
  396.       }
  397.  
  398.       return field_0.createFileExclusively(var0);
  399.    }
  400.  
  401.    public static File createTempFile(String var0, String var1, File var2) throws IOException {
  402.       if (var0 == null) {
  403.          throw new NullPointerException();
  404.       } else if (var0.length() < 3) {
  405.          throw new IllegalArgumentException("Prefix string too short");
  406.       } else {
  407.          String var3 = var1 == null ? ".tmp" : var1;
  408.          Object var4 = tmpFileLock;
  409.          synchronized(var4) {
  410.             if (var2 == null) {
  411.                var2 = new File(getTempDir());
  412.             }
  413.  
  414.             SecurityManager var5 = System.getSecurityManager();
  415.  
  416.             File var6;
  417.             do {
  418.                var6 = generateFile(var0, var3, var2);
  419.             } while(!checkAndCreate(var6.getPath(), var5));
  420.  
  421.             return var6;
  422.          }
  423.       }
  424.    }
  425.  
  426.    public static File createTempFile(String var0, String var1) throws IOException {
  427.       return createTempFile(var0, var1, (File)null);
  428.    }
  429.  
  430.    public int compareTo(File var1) {
  431.       return field_0.compare(this, var1);
  432.    }
  433.  
  434.    public int compareTo(Object var1) {
  435.       return this.compareTo((File)var1);
  436.    }
  437.  
  438.    public boolean equals(Object var1) {
  439.       if (var1 != null && var1 instanceof File) {
  440.          return this.compareTo((File)var1) == 0;
  441.       } else {
  442.          return false;
  443.       }
  444.    }
  445.  
  446.    public int hashCode() {
  447.       return field_0.hashCode(this);
  448.    }
  449.  
  450.    public String toString() {
  451.       return this.getPath();
  452.    }
  453.  
  454.    private synchronized void writeObject(ObjectOutputStream var1) throws IOException {
  455.       var1.defaultWriteObject();
  456.       var1.writeChar(separatorChar);
  457.    }
  458.  
  459.    private synchronized void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  460.       var1.defaultReadObject();
  461.       char var2 = var1.readChar();
  462.       if (var2 != separatorChar) {
  463.          this.path = this.path.replace(var2, separatorChar);
  464.       }
  465.  
  466.       this.path = field_0.normalize(this.path);
  467.       this.prefixLength = field_0.prefixLength(this.path);
  468.    }
  469.  
  470.    static {
  471.       separatorChar = field_0.getSeparator();
  472.       separator = "" + separatorChar;
  473.       pathSeparatorChar = field_0.getPathSeparator();
  474.       pathSeparator = "" + pathSeparatorChar;
  475.       tmpFileLock = new Object();
  476.       counter = -1;
  477.    }
  478. }
  479.