001
014
015 package com.liferay.portal.kernel.nio;
016
017 import java.io.IOException;
018 import java.io.InputStream;
019 import java.io.OutputStream;
020
021 import java.net.URI;
022
023 import java.nio.channels.AsynchronousFileChannel;
024 import java.nio.channels.FileChannel;
025 import java.nio.channels.SeekableByteChannel;
026 import java.nio.file.AccessMode;
027 import java.nio.file.CopyOption;
028 import java.nio.file.DirectoryStream;
029 import java.nio.file.FileStore;
030 import java.nio.file.FileSystem;
031 import java.nio.file.LinkOption;
032 import java.nio.file.OpenOption;
033 import java.nio.file.Path;
034 import java.nio.file.attribute.BasicFileAttributes;
035 import java.nio.file.attribute.FileAttribute;
036 import java.nio.file.attribute.FileAttributeView;
037 import java.nio.file.spi.FileSystemProvider;
038
039 import java.util.Map;
040 import java.util.Set;
041 import java.util.concurrent.ExecutorService;
042
043
046 public class FileSystemProviderWrapper extends FileSystemProvider {
047
048 public FileSystemProviderWrapper(FileSystemProvider fileSystemProvider) {
049 _fileSystemProvider = fileSystemProvider;
050 }
051
052 @Override
053 public void checkAccess(Path path, AccessMode... modes) throws IOException {
054 _fileSystemProvider.checkAccess(PathWrapper.unwrapPath(path), modes);
055 }
056
057 @Override
058 public void copy(
059 Path sourcePath, Path targetPath, CopyOption... copyOptions)
060 throws IOException {
061
062 _fileSystemProvider.copy(
063 PathWrapper.unwrapPath(sourcePath),
064 PathWrapper.unwrapPath(targetPath), copyOptions);
065 }
066
067 @Override
068 public void createDirectory(
069 Path dirPath, FileAttribute<?>... fileAttributes)
070 throws IOException {
071
072 _fileSystemProvider.createDirectory(
073 PathWrapper.unwrapPath(dirPath), fileAttributes);
074 }
075
076 @Override
077 public void createLink(Path linkPath, Path existingPath)
078 throws IOException {
079
080 _fileSystemProvider.createLink(
081 PathWrapper.unwrapPath(linkPath),
082 PathWrapper.unwrapPath(existingPath));
083 }
084
085 @Override
086 public void createSymbolicLink(
087 Path linkPath, Path targetPath, FileAttribute<?>... fileAttributes)
088 throws IOException {
089
090 _fileSystemProvider.createSymbolicLink(
091 PathWrapper.unwrapPath(linkPath),
092 PathWrapper.unwrapPath(targetPath), fileAttributes);
093 }
094
095 @Override
096 public void delete(Path path) throws IOException {
097 _fileSystemProvider.delete(PathWrapper.unwrapPath(path));
098 }
099
100 @Override
101 public boolean deleteIfExists(Path path) throws IOException {
102 return _fileSystemProvider.deleteIfExists(PathWrapper.unwrapPath(path));
103 }
104
105 @Override
106 public <V extends FileAttributeView> V getFileAttributeView(
107 Path path, Class<V> clazz, LinkOption... linkOtions) {
108
109 return _fileSystemProvider.getFileAttributeView(
110 PathWrapper.unwrapPath(path), clazz, linkOtions);
111 }
112
113 @Override
114 public FileStore getFileStore(Path path) throws IOException {
115 return _fileSystemProvider.getFileStore(PathWrapper.unwrapPath(path));
116 }
117
118 @Override
119 public FileSystem getFileSystem(URI uri) {
120 return new FileSystemWrapper(
121 _fileSystemProvider.getFileSystem(uri), this);
122 }
123
124 @Override
125 public Path getPath(URI uri) {
126 Path path = _fileSystemProvider.getPath(uri);
127
128 return new PathWrapper(
129 path, new FileSystemWrapper(path.getFileSystem(), this));
130 }
131
132 @Override
133 public String getScheme() {
134 return _fileSystemProvider.getScheme();
135 }
136
137 @Override
138 public boolean isHidden(Path path) throws IOException {
139 return _fileSystemProvider.isHidden(PathWrapper.unwrapPath(path));
140 }
141
142 @Override
143 public boolean isSameFile(Path path1, Path path2) throws IOException {
144 return _fileSystemProvider.isSameFile(
145 PathWrapper.unwrapPath(path1), PathWrapper.unwrapPath(path2));
146 }
147
148 @Override
149 public void move(
150 Path sourcePath, Path targetPath, CopyOption... copyOptions)
151 throws IOException {
152
153 _fileSystemProvider.move(
154 PathWrapper.unwrapPath(sourcePath),
155 PathWrapper.unwrapPath(targetPath), copyOptions);
156 }
157
158 @Override
159 public AsynchronousFileChannel newAsynchronousFileChannel(
160 Path path, Set<? extends OpenOption> openOptions,
161 ExecutorService executorService, FileAttribute<?>... fileAttribute)
162 throws IOException {
163
164 return _fileSystemProvider.newAsynchronousFileChannel(
165 PathWrapper.unwrapPath(path), openOptions, executorService,
166 fileAttribute);
167 }
168
169 @Override
170 public SeekableByteChannel newByteChannel(
171 Path path, Set<? extends OpenOption> openOptions,
172 FileAttribute<?>... fileAttributes)
173 throws IOException {
174
175 return _fileSystemProvider.newByteChannel(
176 PathWrapper.unwrapPath(path), openOptions, fileAttributes);
177 }
178
179 @Override
180 public DirectoryStream<Path> newDirectoryStream(
181 Path dirPath, DirectoryStream.Filter<? super Path> filter)
182 throws IOException {
183
184 return _fileSystemProvider.newDirectoryStream(
185 PathWrapper.unwrapPath(dirPath), filter);
186 }
187
188 @Override
189 public FileChannel newFileChannel(
190 Path path, Set<? extends OpenOption> openOptions,
191 FileAttribute<?>... fileAttributes)
192 throws IOException {
193
194 return _fileSystemProvider.newFileChannel(
195 PathWrapper.unwrapPath(path), openOptions, fileAttributes);
196 }
197
198 @Override
199 public FileSystem newFileSystem(Path path, Map<String, ?> env)
200 throws IOException {
201
202 return new FileSystemWrapper(
203 _fileSystemProvider.newFileSystem(
204 PathWrapper.unwrapPath(path), env),
205 this);
206 }
207
208 @Override
209 public FileSystem newFileSystem(URI uri, Map<String, ?> env)
210 throws IOException {
211
212 return new FileSystemWrapper(
213 _fileSystemProvider.newFileSystem(uri, env), this);
214 }
215
216 @Override
217 public InputStream newInputStream(Path path, OpenOption... openOptions)
218 throws IOException {
219
220 return _fileSystemProvider.newInputStream(
221 PathWrapper.unwrapPath(path), openOptions);
222 }
223
224 @Override
225 public OutputStream newOutputStream(Path path, OpenOption... openOptions)
226 throws IOException {
227
228 return _fileSystemProvider.newOutputStream(
229 PathWrapper.unwrapPath(path), openOptions);
230 }
231
232 @Override
233 public <A extends BasicFileAttributes> A readAttributes(
234 Path path, Class<A> clazz, LinkOption... linkOptions)
235 throws IOException {
236
237 return _fileSystemProvider.readAttributes(
238 PathWrapper.unwrapPath(path), clazz, linkOptions);
239 }
240
241 @Override
242 public Map<String, Object> readAttributes(
243 Path path, String attributes, LinkOption... linkOptions)
244 throws IOException {
245
246 return _fileSystemProvider.readAttributes(
247 PathWrapper.unwrapPath(path), attributes, linkOptions);
248 }
249
250 @Override
251 public Path readSymbolicLink(Path link) throws IOException {
252 return _fileSystemProvider.readSymbolicLink(
253 PathWrapper.unwrapPath(link));
254 }
255
256 @Override
257 public void setAttribute(
258 Path path, String attribute, Object value,
259 LinkOption... linkOptions)
260 throws IOException {
261
262 _fileSystemProvider.setAttribute(
263 PathWrapper.unwrapPath(path), attribute, value, linkOptions);
264 }
265
266 private final FileSystemProvider _fileSystemProvider;
267
268 }