2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
14 package org.openhab.automation.jsscripting.internal.fs;
16 import java.io.IOException;
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;
30 import org.graalvm.polyglot.io.FileSystem;
33 * Delegate wrapping a {@link FileSystem}
35 * @author Jonathan Gilbert - Initial contribution
37 public class DelegatingFileSystem implements FileSystem {
38 private FileSystemProvider delegate;
40 public DelegatingFileSystem(FileSystemProvider delegate) {
41 this.delegate = delegate;
45 public Path parsePath(URI uri) {
46 return Paths.get(uri);
50 public Path parsePath(String path) {
51 return Paths.get(path);
55 public void checkAccess(Path path, Set<? extends AccessMode> modes, LinkOption... linkOptions) throws IOException {
56 delegate.checkAccess(path, modes.toArray(new AccessMode[0]));
60 public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
61 delegate.createDirectory(dir, attrs);
65 public void delete(Path path) throws IOException {
66 delegate.delete(path);
70 public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)
72 return delegate.newByteChannel(path, options, attrs);
76 public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
78 return delegate.newDirectoryStream(dir, filter);
82 public Path toAbsolutePath(Path path) {
83 return path.toAbsolutePath();
87 public Path toRealPath(Path path, LinkOption... linkOptions) throws IOException {
88 return path.toRealPath(linkOptions);
92 public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException {
93 return delegate.readAttributes(path, attributes, options);