/[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.29 by mkoch, Tue May 6 09:10:19 2003 UTC revision 1.30 by mkoch, Tue May 6 10:06:39 2003 UTC
# Line 145  public class File implements Serializabl Line 145  public class File implements Serializabl
145    public boolean canRead ()    public boolean canRead ()
146    {    {
147      // Test for existence. This also does the SecurityManager check      // Test for existence. This also does the SecurityManager check
148      if (!exists())      if (!exists ())
149        return(false);        return false;
150    
151      return(canReadInternal(path));      return canReadInternal (path);
152    }    }
153    
154    /**    /**
# Line 169  public class File implements Serializabl Line 169  public class File implements Serializabl
169    {    {
170      // We still need to do a SecurityCheck since exists() only checks      // We still need to do a SecurityCheck since exists() only checks
171      // for read access      // for read access
172      SecurityManager sm = System.getSecurityManager();      checkWrite ();
     if (sm != null)  
       sm.checkWrite(path);  
173            
174      // Test for existence.  This is required by the spec      // Test for existence.  This is required by the spec
175      if (!exists())      if (!exists())
# Line 210  public class File implements Serializabl Line 208  public class File implements Serializabl
208     */     */
209    public boolean createNewFile() throws IOException    public boolean createNewFile() throws IOException
210    {    {
211      SecurityManager s = System.getSecurityManager ();      checkWrite ();
       
     if (s != null)  
       s.checkWrite (path);  
       
212      return createInternal (getPath ());      return createInternal (getPath ());
213    }    }
214    
# Line 285  public class File implements Serializabl Line 279  public class File implements Serializabl
279     */     */
280    public boolean exists ()    public boolean exists ()
281    {    {
282      // Check the SecurityManager      checkRead ();
283      SecurityManager sm = System.getSecurityManager();      return existsInternal (path);
     if (sm != null)  
       sm.checkRead(path);  
       
     return(existsInternal(path));  
284    }    }
285    
286    /**    /**
# Line 539  public class File implements Serializabl Line 529  public class File implements Serializabl
529     */     */
530    public boolean isDirectory ()    public boolean isDirectory ()
531    {    {
532      SecurityManager s = System.getSecurityManager ();      checkRead ();
533            return isDirectoryInternal (path);
     if (s != null)  
       s.checkRead (path);  
   
     return isDirectoryInternal(path);  
534    }    }
535    
536    /**    /**
# Line 559  public class File implements Serializabl Line 545  public class File implements Serializabl
545     */     */
546    public boolean isFile ()    public boolean isFile ()
547    {    {
548      SecurityManager s = System.getSecurityManager ();      checkRead ();
       
     if (s != null)  
       s.checkRead(path);  
   
549      return isFileInternal (path);      return isFileInternal (path);
550    }    }
551    
# Line 609  public class File implements Serializabl Line 591  public class File implements Serializabl
591     */     */
592    public long lastModified ()    public long lastModified ()
593    {    {
594      SecurityManager s = System.getSecurityManager ();      checkRead ();
595            return lastModifiedInternal (path);
     if (s != null)  
       s.checkRead (path);  
   
     return lastModifiedInternal(path);  
596    }    }
597    
598    /*    /*
# Line 633  public class File implements Serializabl Line 611  public class File implements Serializabl
611     */     */
612    public long length ()    public long length ()
613    {    {
614      SecurityManager s = System.getSecurityManager ();      checkRead ();
615      if (s != null)      return lengthInternal (path);
       s.checkRead (path);  
   
     return lengthInternal(path);  
616    }    }
617    
618    /*    /*
# Line 675  public class File implements Serializabl Line 650  public class File implements Serializabl
650     */     */
651    public String[] list (FilenameFilter filter)    public String[] list (FilenameFilter filter)
652    {    {
653      // Check the SecurityManager      checkRead ();
     SecurityManager s = System.getSecurityManager ();  
     if (s != null)  
       s.checkRead (path);  
654    
655      // Get the list of files      // Get the list of files
656      String list_path = PlatformHelper.removeTailSeparator(path);      String list_path = PlatformHelper.removeTailSeparator(path);
# Line 691  public class File implements Serializabl Line 663  public class File implements Serializabl
663      if (files == null)      if (files == null)
664        return new String[0];        return new String[0];
665      if (filter == null)      if (filter == null)
666        return(files);        return files;
667            
668      // Apply the filter      // Apply the filter
669      int count = 0;      int count = 0;
# Line 709  public class File implements Serializabl Line 681  public class File implements Serializabl
681        if (files[i] != null)        if (files[i] != null)
682          retfiles[count++] = files[i];          retfiles[count++] = files[i];
683    
684      return(retfiles);      return retfiles;
685    }    }
686    
687    /**    /**
# Line 899  public class File implements Serializabl Line 871  public class File implements Serializabl
871     */     */
872    public boolean mkdir ()    public boolean mkdir ()
873    {    {
874      // Check the SecurityManager      checkWrite ();
875      SecurityManager sm = System.getSecurityManager();      String mk_path = PlatformHelper.removeTailSeparator (path);
876      if (sm != null)      return mkdirInternal (mk_path);
       sm.checkWrite(path);  
   
     String mk_path;  
     mk_path = PlatformHelper.removeTailSeparator(path);  
       
     return(mkdirInternal(mk_path));  
877    }    }
878    
879    /**    /**
# Line 1046  public class File implements Serializabl Line 1012  public class File implements Serializabl
1012    public boolean setReadOnly ()    public boolean setReadOnly ()
1013    {    {
1014      // Test for existence.      // Test for existence.
1015      if (!exists())      if (!exists ())
1016        return(false);        return false;
1017    
1018      // We still need to do a SecurityCheck since exists() only checks      // We still need to do a SecurityCheck since exists() only checks
1019      // for read access      // for read access
1020      SecurityManager sm = System.getSecurityManager();      checkWrite ();
1021      if (sm != null)      return setReadOnlyInternal (path);
       sm.checkWrite(path);  
       
     return setReadOnlyInternal(path);  
1022    }    }
1023    
1024    /**    /**
# Line 1193  public class File implements Serializabl Line 1156  public class File implements Serializabl
1156     */     */
1157    public synchronized boolean renameTo (File dest)    public synchronized boolean renameTo (File dest)
1158    {    {
1159      // Check the SecurityManager      checkWrite ();
     SecurityManager s = System.getSecurityManager ();  
       
     if (s != null)  
       s.checkWrite (path);  
   
1160      // Call our native rename method      // Call our native rename method
1161      boolean rc = renameToInternal(path, dest.getPath());      return renameToInternal (path, dest.getPath ());
   
     return rc;  
1162    }    }
1163    
1164    /*    /*
# Line 1231  public class File implements Serializabl Line 1187  public class File implements Serializabl
1187      if (time < 0)      if (time < 0)
1188        throw new IllegalArgumentException("Negative modification time: " + time);        throw new IllegalArgumentException("Negative modification time: " + time);
1189    
1190        checkWrite ();
1191        return setLastModifiedInternal (path, time);
1192      }
1193    
1194      private void checkWrite ()
1195      {
1196      // Check the SecurityManager      // Check the SecurityManager
1197      SecurityManager s = System.getSecurityManager ();      SecurityManager s = System.getSecurityManager ();
1198        
1199      if (s != null)      if (s != null)
1200        s.checkWrite (path);        s.checkWrite (path);
1201      }
1202    
1203      private void checkRead ()
1204      {
1205        // Check the SecurityManager
1206        SecurityManager s = System.getSecurityManager ();
1207            
1208      return setLastModifiedInternal (path, time);      if (s != null)
1209          s.checkRead (path);
1210    }    }
1211    
1212    /**    /**
# Line 1261  public class File implements Serializabl Line 1231  public class File implements Serializabl
1231      // FIXME: ********IMPLEMENT ME!!!!!!***************      // FIXME: ********IMPLEMENT ME!!!!!!***************
1232      return;      return;
1233    }    }
1234    
1235      private void writeObject (ObjectOutputStream oos) throws IOException
1236      {
1237        oos.defaultWriteObject ();
1238        oos.writeChar (separatorChar);
1239      }
1240    
1241      private void readObject (ObjectInputStream ois)
1242        throws ClassNotFoundException, IOException
1243      {
1244        ois.defaultReadObject ();
1245    
1246        // If the file was from an OS with a different dir separator,
1247        // fixup the path to use the separator on this OS.
1248        char oldSeparatorChar = ois.readChar ();
1249        
1250        if (oldSeparatorChar != separatorChar)
1251          path = path.replace (oldSeparatorChar, separatorChar);
1252      }
1253  } // class File  } // class File
1254    

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

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