jtulach commented on code in PR #9820: URL: https://github.com/apache/netbeans/pull/9820#discussion_r4704563708
########## platform/openide.filesystems/src/org/openide/filesystems/NioPathProvider.java: ########## @@ -0,0 +1,645 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.openide.filesystems; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.ByteArrayOutputStream; +import java.net.URI; +import java.nio.channels.SeekableByteChannel; +import java.nio.channels.FileChannel; +import java.nio.ByteBuffer; +import java.nio.file.AccessDeniedException; +import java.nio.file.AccessMode; +import java.nio.file.CopyOption; +import java.nio.file.DirectoryIteratorException; +import java.nio.file.DirectoryNotEmptyException; +import java.nio.file.DirectoryStream; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.FileStore; +import java.nio.file.FileSystem; +import java.nio.file.LinkOption; +import java.nio.file.NoSuchFileException; +import java.nio.file.NotDirectoryException; +import java.nio.file.OpenOption; +import java.nio.file.Path; +import java.nio.file.ProviderMismatchException; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.FileTime; +import java.nio.file.spi.FileSystemProvider; +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; + +final class NioPathProvider extends FileSystemProvider { + private final NioFsForFileSystem fileSystem; + + NioPathProvider(NioFsForFileSystem fileSystem) { + this.fileSystem = fileSystem; + } + + @Override + public String getScheme() { + return fileSystem.getFileSystem().getRoot().toURI().getScheme(); + } + + @Override + public FileSystem newFileSystem(URI uri, Map<String, ?> env) { + throw new UnsupportedOperationException(); + } + + @Override + public FileSystem getFileSystem(URI uri) { + return fileSystem; + } + + @Override + public Path getPath(URI uri) { + String path = uri.getPath(); + return fileSystem.getPath(path); + } + + @Override + public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, + FileAttribute<?>... attrs) throws IOException { + return NioFileObjectChannel.open(fromPath(path), options, attrs); + } + + @Override + public SeekableByteChannel newByteChannel( + Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { + if (options.stream().anyMatch(option -> + option == java.nio.file.StandardOpenOption.WRITE + || option == java.nio.file.StandardOpenOption.APPEND + || option == java.nio.file.StandardOpenOption.CREATE + || option == java.nio.file.StandardOpenOption.CREATE_NEW)) { + FileObject fo = fromPath(path).getFileObject(); + if (fo == null || !fo.isValid()) { + if (fromPath(path).getFileObject() == null && path.getParent() != null) { + FileObject parent = fromPath(path.getParent()).getFileObject(); + if (parent == null) { + throw new NoSuchFileException(path.toString()); + } + fo = parent.createData(path.getFileName().toString()); + } else { + throw new NoSuchFileException(path.toString()); + } + } + return new WritableFileObjectByteChannel(fo); Review Comment: Done in 2abc58e806 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
