src/solaris/classes/sun/nio/fs/UnixFileSystem.java

Print this page




 285     public PathMatcher getPathMatcher(String syntaxAndInput) {
 286         int pos = syntaxAndInput.indexOf(':');
 287         if (pos <= 0 || pos == syntaxAndInput.length())
 288             throw new IllegalArgumentException();
 289         String syntax = syntaxAndInput.substring(0, pos);
 290         String input = syntaxAndInput.substring(pos+1);
 291 
 292         String expr;
 293         if (syntax.equals(GLOB_SYNTAX)) {
 294             expr = Globs.toUnixRegexPattern(input);
 295         } else {
 296             if (syntax.equals(REGEX_SYNTAX)) {
 297                 expr = input;
 298             } else {
 299                 throw new UnsupportedOperationException("Syntax '" + syntax +
 300                     "' not recognized");
 301             }
 302         }
 303 
 304         // return matcher
 305         final Pattern pattern = Pattern.compile(expr);

 306         return new PathMatcher() {
 307             @Override
 308             public boolean matches(Path path) {
 309                 return pattern.matcher(path.toString()).matches();
 310             }
 311         };
 312     }

 313     private static final String GLOB_SYNTAX = "glob";
 314     private static final String REGEX_SYNTAX = "regex";
 315 
 316 
 317 
 318     @Override
 319     public final UserPrincipalLookupService getUserPrincipalLookupService() {
 320         return LookupService.instance;
 321     }
 322 
 323     private static class LookupService {
 324         static final UserPrincipalLookupService instance =
 325             new UserPrincipalLookupService() {
 326                 @Override
 327                 public UserPrincipal lookupPrincipalByName(String name)
 328                     throws IOException
 329                 {
 330                     return UnixUserPrincipals.lookupUser(name);
 331                 }
 332 
 333                 @Override
 334                 public GroupPrincipal lookupPrincipalByGroupName(String group)
 335                     throws IOException
 336                 {
 337                     return UnixUserPrincipals.lookupGroup(group);
 338                 }
 339             };
 340     }
 341 



































 342 }


 285     public PathMatcher getPathMatcher(String syntaxAndInput) {
 286         int pos = syntaxAndInput.indexOf(':');
 287         if (pos <= 0 || pos == syntaxAndInput.length())
 288             throw new IllegalArgumentException();
 289         String syntax = syntaxAndInput.substring(0, pos);
 290         String input = syntaxAndInput.substring(pos+1);
 291 
 292         String expr;
 293         if (syntax.equals(GLOB_SYNTAX)) {
 294             expr = Globs.toUnixRegexPattern(input);
 295         } else {
 296             if (syntax.equals(REGEX_SYNTAX)) {
 297                 expr = input;
 298             } else {
 299                 throw new UnsupportedOperationException("Syntax '" + syntax +
 300                     "' not recognized");
 301             }
 302         }
 303 
 304         // return matcher
 305         final Pattern pattern = compilePathMatchPattern(expr);
 306 
 307         return new PathMatcher() {
 308             @Override
 309             public boolean matches(Path path) {
 310                 return pattern.matcher(path.toString()).matches();
 311             }
 312         };
 313     }
 314 
 315     private static final String GLOB_SYNTAX = "glob";
 316     private static final String REGEX_SYNTAX = "regex";
 317 


 318     @Override
 319     public final UserPrincipalLookupService getUserPrincipalLookupService() {
 320         return LookupService.instance;
 321     }
 322 
 323     private static class LookupService {
 324         static final UserPrincipalLookupService instance =
 325             new UserPrincipalLookupService() {
 326                 @Override
 327                 public UserPrincipal lookupPrincipalByName(String name)
 328                     throws IOException
 329                 {
 330                     return UnixUserPrincipals.lookupUser(name);
 331                 }
 332 
 333                 @Override
 334                 public GroupPrincipal lookupPrincipalByGroupName(String group)
 335                     throws IOException
 336                 {
 337                     return UnixUserPrincipals.lookupGroup(group);
 338                 }
 339             };
 340     }
 341 
 342     // BsdFileSystem overrides following methods for MacOSX path
 343     Pattern compilePathMatchPattern(String expr) {
 344         return Pattern.compile(expr);
 345     }
 346 
 347     char[] normalizeNativePath(char[] path) {
 348         return path;
 349     }
 350 
 351     String normalizeJavaPath(String path) {
 352         return path;
 353     }
 354 
 355     public int hashCodePath(UnixPath path) {
 356         return sun.misc.Hashing.murmur3_32(path.asByteArray());
 357     }
 358 
 359     int comparePaths(UnixPath path1, UnixPath path2) {
 360         byte[] v1 = path1.asByteArray();
 361         byte[] v2 = path2.asByteArray();
 362         int len1 = v1.length;
 363         int len2 = v2.length;
 364         int n = Math.min(len1, len2);
 365         int k = 0;
 366         while (k < n) {
 367             int c1 = v1[k] & 0xff;
 368             int c2 = v2[k] & 0xff;
 369             if (c1 != c2) {
 370                 return c1 - c2;
 371             }
 372             k++;
 373         }
 374         return len1 - len2;
 375     }
 376 
 377 }