363 * |
363 * |
364 * <p> This method makes use of specialized providers that create pseudo file |
364 * <p> This method makes use of specialized providers that create pseudo file |
365 * systems where the contents of one or more files is treated as a file |
365 * systems where the contents of one or more files is treated as a file |
366 * system. |
366 * system. |
367 * |
367 * |
368 * <p> This method iterates over the {@link FileSystemProvider#installedProviders() |
368 * <p> This method first attempts to locate an installed provider in exactly |
369 * installed} providers. It invokes, in turn, each provider's {@link |
369 * the same manner as the {@link #newFileSystem(Path, Map, ClassLoader) |
370 * FileSystemProvider#newFileSystem(Path,Map) newFileSystem(Path,Map)} method |
370 * newFileSystem(Path, Map, ClassLoader)} method with an empty map. If none |
371 * with an empty map. If a provider returns a file system then the iteration |
371 * of the installed providers return a {@code FileSystem} then an attempt is |
372 * terminates and the file system is returned. If none of the installed |
372 * made to locate the provider using the given class loader. If a provider |
373 * providers return a {@code FileSystem} then an attempt is made to locate |
373 * returns a file system then the lookup terminates and the file system is |
374 * the provider using the given class loader. If a provider returns a file |
374 * returned. |
375 * system then the lookup terminates and the file system is returned. |
|
376 * |
375 * |
377 * @param path |
376 * @param path |
378 * the path to the file |
377 * the path to the file |
379 * @param loader |
378 * @param loader |
380 * the class loader to locate the provider or {@code null} to only |
379 * the class loader to locate the provider or {@code null} to only |
394 */ |
393 */ |
395 public static FileSystem newFileSystem(Path path, |
394 public static FileSystem newFileSystem(Path path, |
396 ClassLoader loader) |
395 ClassLoader loader) |
397 throws IOException |
396 throws IOException |
398 { |
397 { |
|
398 return newFileSystem(path, Map.of(), loader); |
|
399 } |
|
400 |
|
401 /** |
|
402 * Constructs a new {@code FileSystem} to access the contents of a file as a |
|
403 * file system. |
|
404 * |
|
405 * <p> This method makes use of specialized providers that create pseudo file |
|
406 * systems where the contents of one or more files is treated as a file |
|
407 * system. |
|
408 * |
|
409 * <p> This method first attempts to locate an installed provider in exactly |
|
410 * the same manner as the {@link #newFileSystem(Path,Map,ClassLoader) |
|
411 * newFileSystem(Path, Map, ClassLoader)} method. If found, the provider's |
|
412 * {@link FileSystemProvider#newFileSystem(Path, Map) newFileSystem(Path, Map)} |
|
413 * method is invoked to construct the new file system. |
|
414 * |
|
415 * @param path |
|
416 * the path to the file |
|
417 * @param env |
|
418 * a map of provider specific properties to configure the file system; |
|
419 * may be empty |
|
420 * |
|
421 * @return a new file system |
|
422 * |
|
423 * @throws ProviderNotFoundException |
|
424 * if a provider supporting this file type cannot be located |
|
425 * @throws ServiceConfigurationError |
|
426 * when an error occurs while loading a service provider |
|
427 * @throws IOException |
|
428 * if an I/O error occurs |
|
429 * @throws SecurityException |
|
430 * if a security manager is installed and it denies an unspecified |
|
431 * permission |
|
432 * |
|
433 * @since 13 |
|
434 */ |
|
435 public static FileSystem newFileSystem(Path path, Map<String,?> env) |
|
436 throws IOException |
|
437 { |
|
438 return newFileSystem(path, env, null); |
|
439 } |
|
440 |
|
441 /** |
|
442 * Constructs a new {@code FileSystem} to access the contents of a file as a |
|
443 * file system. |
|
444 * |
|
445 * <p> This method makes use of specialized providers that create pseudo file |
|
446 * systems where the contents of one or more files is treated as a file |
|
447 * system. |
|
448 * |
|
449 * <p> This method first attempts to locate an installed provider in exactly |
|
450 * the same manner as the {@link #newFileSystem(Path,Map,ClassLoader) |
|
451 * newFileSystem(Path, Map, ClassLoader)} method. If found, the provider's |
|
452 * {@link FileSystemProvider#newFileSystem(Path, Map) newFileSystem(Path, Map)} |
|
453 * method is invoked with an empty map to construct the new file system. |
|
454 * |
|
455 * @param path |
|
456 * the path to the file |
|
457 * |
|
458 * @return a new file system |
|
459 * |
|
460 * @throws ProviderNotFoundException |
|
461 * if a provider supporting this file type cannot be located |
|
462 * @throws ServiceConfigurationError |
|
463 * when an error occurs while loading a service provider |
|
464 * @throws IOException |
|
465 * if an I/O error occurs |
|
466 * @throws SecurityException |
|
467 * if a security manager is installed and it denies an unspecified |
|
468 * permission |
|
469 * |
|
470 * @since 13 |
|
471 */ |
|
472 public static FileSystem newFileSystem(Path path) throws IOException { |
|
473 return newFileSystem(path, Map.of(), null); |
|
474 } |
|
475 |
|
476 /** |
|
477 * Constructs a new {@code FileSystem} to access the contents of a file as a |
|
478 * file system. |
|
479 * |
|
480 * <p> This method makes use of specialized providers that create pseudo file |
|
481 * systems where the contents of one or more files is treated as a file |
|
482 * system. |
|
483 * |
|
484 * <p> This method iterates over the {@link FileSystemProvider#installedProviders() |
|
485 * installed} providers. It invokes, in turn, each provider's {@link |
|
486 * FileSystemProvider#newFileSystem(Path,Map) newFileSystem(Path,Map)} |
|
487 * method. If a provider returns a file system then the iteration |
|
488 * terminates and the file system is returned. |
|
489 * If none of the installed providers return a {@code FileSystem} then |
|
490 * an attempt is made to locate the provider using the given class loader. |
|
491 * If a provider returns a file |
|
492 * system, then the lookup terminates and the file system is returned. |
|
493 * |
|
494 * @param path |
|
495 * the path to the file |
|
496 * @param env |
|
497 * a map of provider specific properties to configure the file system; |
|
498 * may be empty |
|
499 * @param loader |
|
500 * the class loader to locate the provider or {@code null} to only |
|
501 * attempt to locate an installed provider |
|
502 * |
|
503 * @return a new file system |
|
504 * |
|
505 * @throws ProviderNotFoundException |
|
506 * if a provider supporting this file type cannot be located |
|
507 * @throws ServiceConfigurationError |
|
508 * when an error occurs while loading a service provider |
|
509 * @throws IOException |
|
510 * if an I/O error occurs |
|
511 * @throws SecurityException |
|
512 * if a security manager is installed and it denies an unspecified |
|
513 * permission |
|
514 * |
|
515 * @since 13 |
|
516 */ |
|
517 public static FileSystem newFileSystem(Path path, Map<String,?> env, |
|
518 ClassLoader loader) |
|
519 throws IOException |
|
520 { |
399 if (path == null) |
521 if (path == null) |
400 throw new NullPointerException(); |
522 throw new NullPointerException(); |
401 Map<String,?> env = Collections.emptyMap(); |
|
402 |
|
403 // check installed providers |
523 // check installed providers |
404 for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { |
524 for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { |
405 try { |
525 try { |
406 return provider.newFileSystem(path, env); |
526 return provider.newFileSystem(path, env); |
407 } catch (UnsupportedOperationException uoe) { |
527 } catch (UnsupportedOperationException uoe) { |