81 this.rootDirectory = new UnixPath(this, "/"); 82 } 83 84 // package-private 85 byte[] defaultDirectory() { 86 return defaultDirectory; 87 } 88 89 boolean needToResolveAgainstDefaultDirectory() { 90 return needToResolveAgainstDefaultDirectory; 91 } 92 93 UnixPath rootDirectory() { 94 return rootDirectory; 95 } 96 97 boolean isSolaris() { 98 return false; 99 } 100 101 @Override 102 public final FileSystemProvider provider() { 103 return provider; 104 } 105 106 @Override 107 public final String getSeparator() { 108 return "/"; 109 } 110 111 @Override 112 public final boolean isOpen() { 113 return true; 114 } 115 116 @Override 117 public final boolean isReadOnly() { 118 return false; 119 } 120 152 public Iterator<Path> iterator() { 153 try { 154 SecurityManager sm = System.getSecurityManager(); 155 if (sm != null) 156 sm.checkRead(rootDirectory.toString()); 157 return allowedList.iterator(); 158 } catch (SecurityException x) { 159 List<Path> disallowed = Collections.emptyList(); 160 return disallowed.iterator(); 161 } 162 } 163 }; 164 } 165 166 /** 167 * Returns object to iterate over entries in mounttab or equivalent 168 */ 169 abstract Iterable<UnixMountEntry> getMountEntries(); 170 171 /** 172 * Returns a FileStore to represent the file system where the given file 173 * reside. 174 */ 175 abstract FileStore getFileStore(UnixPath path) throws IOException; 176 177 /** 178 * Returns a FileStore to represent the file system for the given mount 179 * mount. 180 */ 181 abstract FileStore getFileStore(UnixMountEntry entry) throws IOException; 182 183 /** 184 * Iterator returned by getFileStores method. 185 */ 186 private class FileStoreIterator implements Iterator<FileStore> { 187 private final Iterator<UnixMountEntry> entries; 188 private FileStore next; 189 190 FileStoreIterator() { 191 this.entries = getMountEntries().iterator(); 192 } 193 194 private FileStore readNext() { 195 assert Thread.holdsLock(this); 196 for (;;) { 197 if (!entries.hasNext()) 247 } 248 249 @Override 250 public final Iterable<FileStore> getFileStores() { 251 SecurityManager sm = System.getSecurityManager(); 252 if (sm != null) { 253 try { 254 sm.checkPermission(new RuntimePermission("getFileStoreAttributes")); 255 } catch (SecurityException se) { 256 return Collections.emptyList(); 257 } 258 } 259 return new Iterable<FileStore>() { 260 public Iterator<FileStore> iterator() { 261 return new FileStoreIterator(); 262 } 263 }; 264 } 265 266 @Override 267 public final UnixPath getPath(String path) { 268 return new UnixPath(this, path); 269 } 270 271 @Override 272 public PathMatcher getPathMatcher(String syntaxAndInput) { 273 int pos = syntaxAndInput.indexOf(':'); 274 if (pos <= 0 || pos == syntaxAndInput.length()) 275 throw new IllegalArgumentException(); 276 String syntax = syntaxAndInput.substring(0, pos); 277 String input = syntaxAndInput.substring(pos+1); 278 279 String expr; 280 if (syntax.equals(GLOB_SYNTAX)) { 281 expr = Globs.toUnixRegexPattern(input); 282 } else { 283 if (syntax.equals(REGEX_SYNTAX)) { 284 expr = input; 285 } else { 286 throw new UnsupportedOperationException("Syntax '" + syntax + 287 "' not recognized"); 288 } 289 } 290 291 // return matcher 292 final Pattern pattern = Pattern.compile(expr); 293 return new PathMatcher() { 294 @Override 295 public boolean matches(Path path) { 296 return pattern.matcher(path.toString()).matches(); 297 } 298 }; 299 } 300 private static final String GLOB_SYNTAX = "glob"; 301 private static final String REGEX_SYNTAX = "regex"; 302 303 protected boolean followLinks(LinkOption... options) { 304 boolean followLinks = true; 305 for (LinkOption option: options) { 306 if (option == LinkOption.NOFOLLOW_LINKS) { 307 followLinks = false; 308 continue; 309 } 310 if (option == null) 311 throw new NullPointerException(); 312 throw new AssertionError("Should not get here"); 313 } 314 return followLinks; 315 } 316 317 @SuppressWarnings("unchecked") 318 protected <V extends FileAttributeView> V newFileAttributeView(Class<V> view, 319 UnixPath file, 320 LinkOption... options) 321 { 322 if (view == null) 323 throw new NullPointerException(); 324 boolean followLinks = followLinks(options); 325 Class<?> c = view; 326 if (c == BasicFileAttributeView.class) 327 return (V) UnixFileAttributeViews.createBasicView(file, followLinks); 328 if (c == PosixFileAttributeView.class) 329 return (V) UnixFileAttributeViews.createPosixView(file, followLinks); 330 if (c == FileOwnerAttributeView.class) 331 return (V) UnixFileAttributeViews.createOwnerView(file, followLinks); 332 return (V) null; 333 } 334 335 static List<String> standardFileAttributeViews() { 336 return Arrays.asList("basic", "posix", "unix", "owner"); 337 } 338 339 protected DynamicFileAttributeView newFileAttributeView(String name, 340 UnixPath file, 341 LinkOption... options) 342 { 343 boolean followLinks = followLinks(options); 344 if (name.equals("basic")) 345 return UnixFileAttributeViews.createBasicView(file, followLinks); 346 if (name.equals("posix")) 347 return UnixFileAttributeViews.createPosixView(file, followLinks); 348 if (name.equals("unix")) 349 return UnixFileAttributeViews.createUnixView(file, followLinks); 350 if (name.equals("owner")) 351 return UnixFileAttributeViews.createOwnerView(file, followLinks); 352 return null; 353 } 354 355 @Override 356 public final UserPrincipalLookupService getUserPrincipalLookupService() { 357 return theLookupService; 358 } 359 360 private static final UserPrincipalLookupService theLookupService = 361 new UserPrincipalLookupService() { 362 @Override 363 public UserPrincipal lookupPrincipalByName(String name) 364 throws IOException 365 { 366 return UnixUserPrincipals.lookupUser(name); 367 } 368 369 @Override 370 public GroupPrincipal lookupPrincipalByGroupName(String group) 371 throws IOException 372 { 373 return UnixUserPrincipals.lookupGroup(group); 374 } 375 }; 376 } | 81 this.rootDirectory = new UnixPath(this, "/"); 82 } 83 84 // package-private 85 byte[] defaultDirectory() { 86 return defaultDirectory; 87 } 88 89 boolean needToResolveAgainstDefaultDirectory() { 90 return needToResolveAgainstDefaultDirectory; 91 } 92 93 UnixPath rootDirectory() { 94 return rootDirectory; 95 } 96 97 boolean isSolaris() { 98 return false; 99 } 100 101 static List<String> standardFileAttributeViews() { 102 return Arrays.asList("basic", "posix", "unix", "owner"); 103 } 104 105 @Override 106 public final FileSystemProvider provider() { 107 return provider; 108 } 109 110 @Override 111 public final String getSeparator() { 112 return "/"; 113 } 114 115 @Override 116 public final boolean isOpen() { 117 return true; 118 } 119 120 @Override 121 public final boolean isReadOnly() { 122 return false; 123 } 124 156 public Iterator<Path> iterator() { 157 try { 158 SecurityManager sm = System.getSecurityManager(); 159 if (sm != null) 160 sm.checkRead(rootDirectory.toString()); 161 return allowedList.iterator(); 162 } catch (SecurityException x) { 163 List<Path> disallowed = Collections.emptyList(); 164 return disallowed.iterator(); 165 } 166 } 167 }; 168 } 169 170 /** 171 * Returns object to iterate over entries in mounttab or equivalent 172 */ 173 abstract Iterable<UnixMountEntry> getMountEntries(); 174 175 /** 176 * Returns a FileStore to represent the file system for the given mount 177 * mount. 178 */ 179 abstract FileStore getFileStore(UnixMountEntry entry) throws IOException; 180 181 /** 182 * Iterator returned by getFileStores method. 183 */ 184 private class FileStoreIterator implements Iterator<FileStore> { 185 private final Iterator<UnixMountEntry> entries; 186 private FileStore next; 187 188 FileStoreIterator() { 189 this.entries = getMountEntries().iterator(); 190 } 191 192 private FileStore readNext() { 193 assert Thread.holdsLock(this); 194 for (;;) { 195 if (!entries.hasNext()) 245 } 246 247 @Override 248 public final Iterable<FileStore> getFileStores() { 249 SecurityManager sm = System.getSecurityManager(); 250 if (sm != null) { 251 try { 252 sm.checkPermission(new RuntimePermission("getFileStoreAttributes")); 253 } catch (SecurityException se) { 254 return Collections.emptyList(); 255 } 256 } 257 return new Iterable<FileStore>() { 258 public Iterator<FileStore> iterator() { 259 return new FileStoreIterator(); 260 } 261 }; 262 } 263 264 @Override 265 public final Path getPath(String first, String... more) { 266 String path; 267 if (more.length == 0) { 268 path = first; 269 } else { 270 StringBuilder sb = new StringBuilder(); 271 sb.append(first); 272 for (String segment: more) { 273 if (segment.length() > 0) { 274 if (sb.length() > 0) 275 sb.append('/'); 276 sb.append(segment); 277 } 278 } 279 path = sb.toString(); 280 } 281 return new UnixPath(this, path); 282 } 283 284 @Override 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 } |