< prev index next >

src/java.base/unix/classes/java/io/UnixFileSystem.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


  81         return sb.toString();
  82     }
  83 
  84     /* Check that the given pathname is normal.  If not, invoke the real
  85        normalizer on the part of the pathname that requires normalization.
  86        This way we iterate through the whole pathname string only once. */
  87     public String normalize(String pathname) {
  88         int n = pathname.length();
  89         char prevChar = 0;
  90         for (int i = 0; i < n; i++) {
  91             char c = pathname.charAt(i);
  92             if ((prevChar == '/') && (c == '/'))
  93                 return normalize(pathname, n, i - 1);
  94             prevChar = c;
  95         }
  96         if (prevChar == '/') return normalize(pathname, n, n - 1);
  97         return pathname;
  98     }
  99 
 100     public int prefixLength(String pathname) {
 101         if (pathname.length() == 0) return 0;
 102         return (pathname.charAt(0) == '/') ? 1 : 0;
 103     }
 104 
 105     public String resolve(String parent, String child) {
 106         if (child.isEmpty()) return parent;
 107         if (child.charAt(0) == '/') {
 108             if (parent.equals("/")) return child;
 109             return parent + child;
 110         }
 111         if (parent.equals("/")) return parent + child;
 112         return parent + '/' + child;
 113     }
 114 
 115     public String getDefaultParent() {
 116         return "/";
 117     }
 118 
 119     public String fromURIPath(String path) {
 120         String p = path;
 121         if (p.endsWith("/") && (p.length() > 1)) {


 232                     // toward the end
 233                     return null;
 234                 }
 235                 return path.substring(0, idx);
 236             } else {
 237                 ++nonDotCount;
 238                 adjacentDots = 0;
 239             }
 240             --idx;
 241         }
 242         return null;
 243     }
 244 
 245     /* -- Attribute accessors -- */
 246 
 247     public native int getBooleanAttributes0(File f);
 248 
 249     public int getBooleanAttributes(File f) {
 250         int rv = getBooleanAttributes0(f);
 251         String name = f.getName();
 252         boolean hidden = (name.length() > 0) && (name.charAt(0) == '.');
 253         return rv | (hidden ? BA_HIDDEN : 0);
 254     }
 255 
 256     public native boolean checkAccess(File f, int access);
 257     public native long getLastModifiedTime(File f);
 258     public native long getLength(File f);
 259     public native boolean setPermission(File f, int access, boolean enable, boolean owneronly);
 260 
 261     /* -- File operations -- */
 262 
 263     public native boolean createFileExclusively(String path)
 264         throws IOException;
 265     public boolean delete(File f) {
 266         // Keep canonicalization caches in sync after file deletion
 267         // and renaming operations. Could be more clever than this
 268         // (i.e., only remove/update affected entries) but probably
 269         // not worth it since these entries expire after 30 seconds
 270         // anyway.
 271         if (useCanonCaches) {
 272             cache.clear();




  81         return sb.toString();
  82     }
  83 
  84     /* Check that the given pathname is normal.  If not, invoke the real
  85        normalizer on the part of the pathname that requires normalization.
  86        This way we iterate through the whole pathname string only once. */
  87     public String normalize(String pathname) {
  88         int n = pathname.length();
  89         char prevChar = 0;
  90         for (int i = 0; i < n; i++) {
  91             char c = pathname.charAt(i);
  92             if ((prevChar == '/') && (c == '/'))
  93                 return normalize(pathname, n, i - 1);
  94             prevChar = c;
  95         }
  96         if (prevChar == '/') return normalize(pathname, n, n - 1);
  97         return pathname;
  98     }
  99 
 100     public int prefixLength(String pathname) {
 101         if (pathname.isEmpty()) return 0;
 102         return (pathname.charAt(0) == '/') ? 1 : 0;
 103     }
 104 
 105     public String resolve(String parent, String child) {
 106         if (child.isEmpty()) return parent;
 107         if (child.charAt(0) == '/') {
 108             if (parent.equals("/")) return child;
 109             return parent + child;
 110         }
 111         if (parent.equals("/")) return parent + child;
 112         return parent + '/' + child;
 113     }
 114 
 115     public String getDefaultParent() {
 116         return "/";
 117     }
 118 
 119     public String fromURIPath(String path) {
 120         String p = path;
 121         if (p.endsWith("/") && (p.length() > 1)) {


 232                     // toward the end
 233                     return null;
 234                 }
 235                 return path.substring(0, idx);
 236             } else {
 237                 ++nonDotCount;
 238                 adjacentDots = 0;
 239             }
 240             --idx;
 241         }
 242         return null;
 243     }
 244 
 245     /* -- Attribute accessors -- */
 246 
 247     public native int getBooleanAttributes0(File f);
 248 
 249     public int getBooleanAttributes(File f) {
 250         int rv = getBooleanAttributes0(f);
 251         String name = f.getName();
 252         boolean hidden = !name.isEmpty() && name.charAt(0) == '.';
 253         return rv | (hidden ? BA_HIDDEN : 0);
 254     }
 255 
 256     public native boolean checkAccess(File f, int access);
 257     public native long getLastModifiedTime(File f);
 258     public native long getLength(File f);
 259     public native boolean setPermission(File f, int access, boolean enable, boolean owneronly);
 260 
 261     /* -- File operations -- */
 262 
 263     public native boolean createFileExclusively(String path)
 264         throws IOException;
 265     public boolean delete(File f) {
 266         // Keep canonicalization caches in sync after file deletion
 267         // and renaming operations. Could be more clever than this
 268         // (i.e., only remove/update affected entries) but probably
 269         // not worth it since these entries expire after 30 seconds
 270         // anyway.
 271         if (useCanonCaches) {
 272             cache.clear();


< prev index next >