29
29
import java .util .List ;
30
30
import java .util .Map ;
31
31
import java .util .Set ;
32
- import java .util .function .BiPredicate ;
33
32
import java .util .stream .Stream ;
34
33
35
34
public class UnionFileSystemProvider extends FileSystemProvider {
@@ -73,24 +72,7 @@ protected Path uriToPath(URI uri) {
73
72
*/
74
73
@ Override
75
74
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 );
94
76
}
95
77
96
78
/**
@@ -105,8 +87,7 @@ public FileSystem newFileSystem(final URI uri, final Map<String, ?> env) throws
105
87
public FileSystem newFileSystem (final Path path , final Map <String , ?> env ) throws IOException {
106
88
@ SuppressWarnings ("unchecked" )
107
89
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 );
110
91
111
92
if (filter == null && additional .isEmpty ())
112
93
throw new UnsupportedOperationException ("Missing additional and/or filter" );
@@ -119,6 +100,19 @@ public FileSystem newFileSystem(final Path path, final Map<String, ?> env) throw
119
100
}
120
101
}
121
102
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
+
122
116
public UnionFileSystem newFileSystem (@ Nullable UnionPathFilter pathfilter , final Path ... paths ) {
123
117
if (paths .length == 0 ) throw new IllegalArgumentException ("Need at least one path" );
124
118
var key = makeKey (paths [0 ]);
0 commit comments