]> git.basschouten.com Git - openhab-addons.git/blob
2f49c4d7fc398e2e0646538750ac7ec92b8e8e52
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13
14 package org.openhab.automation.jsscripting.internal.fs;
15
16 import java.io.IOException;
17 import java.net.URI;
18 import java.nio.channels.SeekableByteChannel;
19 import java.nio.file.AccessMode;
20 import java.nio.file.DirectoryStream;
21 import java.nio.file.LinkOption;
22 import java.nio.file.OpenOption;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25 import java.nio.file.attribute.FileAttribute;
26 import java.nio.file.spi.FileSystemProvider;
27 import java.util.Map;
28 import java.util.Set;
29
30 import org.graalvm.polyglot.io.FileSystem;
31
32 /**
33  * Delegate wrapping a {@link FileSystem}
34  *
35  * @author Jonathan Gilbert - Initial contribution
36  */
37 public class DelegatingFileSystem implements FileSystem {
38     private FileSystemProvider delegate;
39
40     public DelegatingFileSystem(FileSystemProvider delegate) {
41         this.delegate = delegate;
42     }
43
44     @Override
45     public Path parsePath(URI uri) {
46         return Paths.get(uri);
47     }
48
49     @Override
50     public Path parsePath(String path) {
51         return Paths.get(path);
52     }
53
54     @Override
55     public void checkAccess(Path path, Set<? extends AccessMode> modes, LinkOption... linkOptions) throws IOException {
56         delegate.checkAccess(path, modes.toArray(new AccessMode[0]));
57     }
58
59     @Override
60     public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
61         delegate.createDirectory(dir, attrs);
62     }
63
64     @Override
65     public void delete(Path path) throws IOException {
66         delegate.delete(path);
67     }
68
69     @Override
70     public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)
71             throws IOException {
72         return delegate.newByteChannel(path, options, attrs);
73     }
74
75     @Override
76     public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
77             throws IOException {
78         return delegate.newDirectoryStream(dir, filter);
79     }
80
81     @Override
82     public Path toAbsolutePath(Path path) {
83         return path.toAbsolutePath();
84     }
85
86     @Override
87     public Path toRealPath(Path path, LinkOption... linkOptions) throws IOException {
88         return path.toRealPath(linkOptions);
89     }
90
91     @Override
92     public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException {
93         return delegate.readAttributes(path, attributes, options);
94     }
95 }