use of java.nio.file.DirectoryStream.Filter in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method newByteChannel.
/* (non-Javadoc)
* @see java.nio.file.spi.FileSystemProvider#newByteChannel(java.nio.file.Path, java.util.Set, java.nio.file.attribute.FileAttribute[])
*/
@Override
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
if (attrs.length > 0) {
throw new UnsupportedOperationException("Atomically setting of file attributes is not supported.");
}
MCRPath ifsPath = MCRFileSystemUtils.checkPathAbsolute(path);
Set<? extends OpenOption> fileOpenOptions = options.stream().filter(option -> !(option == StandardOpenOption.CREATE || option == StandardOpenOption.CREATE_NEW)).collect(Collectors.toSet());
boolean create = options.contains(StandardOpenOption.CREATE);
boolean createNew = options.contains(StandardOpenOption.CREATE_NEW);
if (create || createNew) {
for (OpenOption option : fileOpenOptions) {
// check before we create any file instance
MCRFile.checkOpenOption(option);
}
}
MCRFile mcrFile = MCRFileSystemUtils.getMCRFile(ifsPath, create, createNew);
if (mcrFile == null) {
throw new NoSuchFileException(path.toString());
}
return mcrFile.getFileChannel(fileOpenOptions);
}
Aggregations