/[classpath]/classpath/java/io/File.java
ViewVC logotype

Diff of /classpath/java/io/File.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.33 by rupp, Sat Jul 19 12:36:31 2003 UTC revision 1.34 by rupp, Thu Jul 31 09:15:02 2003 UTC
# Line 180  public class File implements Serializabl Line 180  public class File implements Serializabl
180      else      else
181        try        try
182          {          {
183            File test = createTempFile ("tst", null, this);            /* If the separator is '\' a DOS-style-filesystem is assumed
184                 and a short name is used, otherwise use a long name.
185                 WARNGIN: some implementation of DOS-style-filesystems also
186                 accept '/' as separator. In that case the following code
187                 will fail.
188              */
189              String filename = (separatorChar!='\\')?"test-dir-write":"tst";
190              File test = createTempFile (filename, null, this);
191            return (test != null && test.delete ());            return (test != null && test.delete ());
192          }          }
193        catch (IOException ioe)        catch (IOException ioe)
# Line 961  public class File implements Serializabl Line 968  public class File implements Serializabl
968                                   + " is not really a directory.");                                   + " is not really a directory.");
969        }        }
970    
971      // Now process the prefix and suffix.      // Check if prefix is at least 3 characters long
972      if (prefix.length () < 3)      if (prefix.length () < 3)
973        throw new IllegalArgumentException ("Prefix too short: " + prefix + "(valid length 3..7)");        throw new IllegalArgumentException ("Prefix too short: " + prefix);
     if (prefix.length() >= 8)  
       throw new IllegalArgumentException("Prefix too long: " + prefix + "(valid length 3..7)");  
974    
975        // Set default value of suffix
976      if (suffix == null)      if (suffix == null)
977        suffix = ".tmp";        suffix = ".tmp";
978    
979      // Now identify a file name and make sure it doesn't exist (limit the name to 8 for DOS-compatibility)      /* Now identify a file name and make sure it doesn't exist.
980      File f;         If the separator is '\' a DOS-style-filesystem is assumed and
981      int  mask = (int)(0x000000ffffFFFFL >> (long)(prefix.length() * 4));         a 8+3-filename is used, otherwise use a long name.
982      for(;;)         WARNGIN: some implementation of DOS-style-filesystems also
983           accept '/' as separator. In that case the following code
984           will fail.
985        */
986        File file;
987        if (separatorChar!='\\')
988          {      
989            // probably a non-DOS-filesystem, use long names
990            do
991              {
992                String filename = prefix + System.currentTimeMillis () + suffix;
993                file = new File (directory, filename);
994              }
995            while (file.exists ());
996          }
997        else
998        {        {
999          int n = (int)(System.currentTimeMillis() & mask);          // probably a DOS-filesystem, use short names (8+3)
         String filename = prefix + java.lang.Integer.toHexString(n) + suffix;  
         f = new File(directory, filename);  
1000    
1001          if (f.exists())          // make sure prefix is not longer than 7 characters
1002            continue;          if (prefix.length() >= 8)
1003          else            throw new IllegalArgumentException("Prefix too long: " + prefix + "(valid length 3..7)");
1004            break;  
1005            int  mask = (int)(0x000000ffffFFFFL >> (long)(prefix.length() * 4));
1006            do
1007              {
1008                int n = (int)(System.currentTimeMillis() & mask);
1009                String filename = prefix + java.lang.Integer.toHexString(n) + suffix;
1010                file = new File(directory, filename);
1011              }
1012            while (file.exists ());
1013        }        }
1014    
1015      // Verify that we are allowed to create this file      // Verify that we are allowed to create this file
1016      SecurityManager sm = System.getSecurityManager();      SecurityManager sm = System.getSecurityManager();
1017      if (sm != null)      if (sm != null)
1018        sm.checkWrite(f.getAbsolutePath());        sm.checkWrite(file.getAbsolutePath());
1019    
1020      // Now create the file and return our file object      // Now create the file and return our file object
1021      createInternal(f.getAbsolutePath());      createInternal(file.getAbsolutePath());
1022      return f;      return file;
1023    }    }
1024    
1025    /*    /*

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.34

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26