Search in sources :

Example 1 with Filter

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);
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) LoadingCache(com.google.common.cache.LoadingCache) FileTime(java.nio.file.attribute.FileTime) MCRFileAttributes(org.mycore.datamodel.niofs.MCRFileAttributes) DirectoryStream(java.nio.file.DirectoryStream) MCRMD5AttributeView(org.mycore.datamodel.niofs.MCRMD5AttributeView) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) Map(java.util.Map) URI(java.net.URI) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) MCRPath(org.mycore.datamodel.niofs.MCRPath) FileAttributeView(java.nio.file.attribute.FileAttributeView) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) FileAttribute(java.nio.file.attribute.FileAttribute) FileSystem(java.nio.file.FileSystem) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) CacheLoader(com.google.common.cache.CacheLoader) SeekableByteChannel(java.nio.channels.SeekableByteChannel) FileSystemAlreadyExistsException(java.nio.file.FileSystemAlreadyExistsException) Logger(org.apache.logging.log4j.Logger) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) AccessDeniedException(java.nio.file.AccessDeniedException) MCRContentStoreFactory(org.mycore.datamodel.ifs.MCRContentStoreFactory) CopyOption(java.nio.file.CopyOption) HashMap(java.util.HashMap) MCRConfiguration(org.mycore.common.config.MCRConfiguration) FileSystemProvider(java.nio.file.spi.FileSystemProvider) MCRAbstractFileSystem(org.mycore.datamodel.niofs.MCRAbstractFileSystem) AccessMode(java.nio.file.AccessMode) StandardCopyOption(java.nio.file.StandardCopyOption) HashSet(java.util.HashSet) LinkOption(java.nio.file.LinkOption) InvalidPathException(java.nio.file.InvalidPathException) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Filter(java.nio.file.DirectoryStream.Filter) MCRFile(org.mycore.datamodel.ifs.MCRFile) FileStore(java.nio.file.FileStore) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) Files(java.nio.file.Files) OpenOption(java.nio.file.OpenOption) NotDirectoryException(java.nio.file.NotDirectoryException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) StandardOpenOption(java.nio.file.StandardOpenOption) OpenOption(java.nio.file.OpenOption) MCRFile(org.mycore.datamodel.ifs.MCRFile) NoSuchFileException(java.nio.file.NoSuchFileException) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Aggregations

CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 Sets (com.google.common.collect.Sets)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 SeekableByteChannel (java.nio.channels.SeekableByteChannel)1 AccessDeniedException (java.nio.file.AccessDeniedException)1 AccessMode (java.nio.file.AccessMode)1 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)1 CopyOption (java.nio.file.CopyOption)1 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 DirectoryStream (java.nio.file.DirectoryStream)1 Filter (java.nio.file.DirectoryStream.Filter)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 FileStore (java.nio.file.FileStore)1 FileSystem (java.nio.file.FileSystem)1 FileSystemAlreadyExistsException (java.nio.file.FileSystemAlreadyExistsException)1