2929import java .util .List ;
3030import java .util .Map ;
3131import java .util .Set ;
32- import java .util .function .BiPredicate ;
3332import java .util .stream .Stream ;
3433
3534public class UnionFileSystemProvider extends FileSystemProvider {
@@ -73,24 +72,7 @@ protected Path uriToPath(URI uri) {
7372 */
7473 @ Override
7574 public FileSystem newFileSystem (final URI uri , final Map <String , ?> env ) throws IOException {
76- @ SuppressWarnings ("unchecked" )
77- var additional = ((Map <String , List <Path >>)env ).getOrDefault ("additional" , List .<Path >of ());
78- @ SuppressWarnings ("unchecked" )
79- var filter = ((Map <String , UnionPathFilter >)env ).getOrDefault ("filter" , null );
80-
81- if (filter == null && additional .isEmpty ())
82- throw new IllegalArgumentException ("Missing additional and/or filter" );
83-
84- if (filter == null )
85- filter = (p , b ) -> true ;
86-
87- var path = uriToPath (uri );
88- var key = makeKey (path );
89- try {
90- return newFileSystemInternal (key , filter , Stream .concat (Stream .of (path ), additional .stream ()).toArray (Path []::new ));
91- } catch (UncheckedIOException e ) {
92- throw e .getCause ();
93- }
75+ return newFileSystem (uriToPath (uri ), env );
9476 }
9577
9678 /**
@@ -105,8 +87,7 @@ public FileSystem newFileSystem(final URI uri, final Map<String, ?> env) throws
10587 public FileSystem newFileSystem (final Path path , final Map <String , ?> env ) throws IOException {
10688 @ SuppressWarnings ("unchecked" )
10789 var additional = ((Map <String , List <Path >>)env ).getOrDefault ("additional" , List .<Path >of ());
108- @ SuppressWarnings ("unchecked" )
109- var filter = ((Map <String , UnionPathFilter >)env ).getOrDefault ("filter" , null );
90+ var filter = readFilterFromEnv (env );
11091
11192 if (filter == null && additional .isEmpty ())
11293 throw new UnsupportedOperationException ("Missing additional and/or filter" );
@@ -119,6 +100,19 @@ public FileSystem newFileSystem(final Path path, final Map<String, ?> env) throw
119100 }
120101 }
121102
103+ @ Nullable
104+ private static UnionPathFilter readFilterFromEnv (Map <String , ?> env ) {
105+ Object filter = env .get ("filter" );
106+
107+ if (filter == null ) {
108+ return null ;
109+ } else if (filter instanceof UnionPathFilter unionPathFilter ) {
110+ return unionPathFilter ;
111+ } else {
112+ throw new IllegalArgumentException ("Unknown type for \" filter\" UnionFileSystem env var: " + filter .getClass ().getName ());
113+ }
114+ }
115+
122116 public UnionFileSystem newFileSystem (@ Nullable UnionPathFilter pathfilter , final Path ... paths ) {
123117 if (paths .length == 0 ) throw new IllegalArgumentException ("Need at least one path" );
124118 var key = makeKey (paths [0 ]);
0 commit comments