-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
DelegatingFileSystem.java
208 lines (180 loc) · 5.48 KB
/
DelegatingFileSystem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.io.fs;
import java.io.IOException;
import java.net.URI;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.WatchService;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.nio.file.spi.FileSystemProvider;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public abstract class DelegatingFileSystem extends FileSystem
{
private final FileSystem delegate;
private final FileSystemProvider provider;
public DelegatingFileSystem( final FileSystem delegate )
{
this.delegate = delegate;
FileSystemProvider delegateProvider = delegate.provider();
this.provider = ( delegateProvider == null ) ? null : createDelegate( delegateProvider );
}
public FileSystem getDelegate()
{
return delegate;
}
@Override
public FileSystemProvider provider()
{
return provider;
}
@Override
public void close() throws IOException
{
delegate.close();
}
@Override
public boolean isOpen()
{
return delegate.isOpen();
}
@Override
public boolean isReadOnly()
{
return delegate.isReadOnly();
}
@Override
public String getSeparator()
{
return delegate.getSeparator();
}
@Override
public Iterable<Path> getRootDirectories()
{
final Iterable<Path> rootDirectories = delegate.getRootDirectories();
return new Iterable<Path>()
{
@Override
public Iterator<Path> iterator()
{
final Iterator<Path> iterator = rootDirectories.iterator();
return new Iterator<Path>()
{
@Override
public boolean hasNext()
{
return iterator.hasNext();
}
@Override
public Path next()
{
return createDelegate( iterator.next() );
}
@Override
public void remove()
{
iterator.remove();
}
};
}
};
}
@Override
public Iterable<FileStore> getFileStores()
{
return delegate.getFileStores();
}
@Override
public Set<String> supportedFileAttributeViews()
{
return delegate.supportedFileAttributeViews();
}
@Override
public Path getPath( String first, String... more )
{
return createDelegate( delegate.getPath( first, more ) );
}
@Override
public PathMatcher getPathMatcher( String syntaxAndPattern )
{
final PathMatcher matcher = delegate.getPathMatcher( syntaxAndPattern );
return path -> matcher.matches( DelegatingPath.getDelegate( path ) );
}
@Override
public UserPrincipalLookupService getUserPrincipalLookupService()
{
return delegate.getUserPrincipalLookupService();
}
@Override
public WatchService newWatchService() throws IOException
{
throw new UnsupportedOperationException();
}
protected Path createDelegate( Path path )
{
return new WrappedPath( path, this );
}
protected DelegatingFileSystemProvider createDelegate( FileSystemProvider provider )
{
return new WrappedProvider( provider, this );
}
public static class WrappedPath extends DelegatingPath
{
private final DelegatingFileSystem fileSystem;
WrappedPath( Path delegate, DelegatingFileSystem fileSystem )
{
super( delegate, fileSystem );
this.fileSystem = fileSystem;
}
@Override
protected Path createDelegate( Path path )
{
return fileSystem.createDelegate( path );
}
}
public static class WrappedProvider extends DelegatingFileSystemProvider
{
private final DelegatingFileSystem fileSystem;
public WrappedProvider( FileSystemProvider delegate, DelegatingFileSystem fileSystem )
{
super( delegate );
this.fileSystem = fileSystem;
}
@Override
public FileSystem newFileSystem( URI uri, Map<String, ?> env ) throws IOException
{
throw new UnsupportedOperationException();
}
@Override
public FileSystem getFileSystem( URI uri )
{
throw new UnsupportedOperationException();
}
@Override
protected Path createDelegate( Path path )
{
return fileSystem.createDelegate( path );
}
}
}