Search in sources :

Example 56 with MCRPath

use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.

the class MCRCStoreIFS2 method getParentDirectory.

private MCRDirectory getParentDirectory(String storageID) throws UncheckedIOException {
    MCRPath relPath = MCRPath.getPath("", toPath(storageID));
    String parentPath = relPath.getParent().getOwnerRelativePath();
    MCRFileCollection slot;
    try {
        slot = getSlot(toDerivateID(storageID));
        return (MCRDirectory) slot.getNodeByPath(parentPath);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 57 with MCRPath

use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.

the class MCRFileSystemProvider method newDirectoryStream.

/* (non-Javadoc)
     * @see java.nio.file.spi.FileSystemProvider#newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter)
     */
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
    MCRFilesystemNode node = resolvePath(mcrPath);
    if (node instanceof MCRDirectory) {
        return new MCRDirectoryStream((MCRDirectory) node, mcrPath);
    }
    throw new NotDirectoryException(dir.toString());
}
Also used : NotDirectoryException(java.nio.file.NotDirectoryException) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 58 with MCRPath

use of org.mycore.datamodel.niofs.MCRPath 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)

Example 59 with MCRPath

use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.

the class MCRFileSystemProvider method createDirectory.

/* (non-Javadoc)
     * @see java.nio.file.spi.FileSystemProvider#createDirectory(java.nio.file.Path, java.nio.file.attribute.FileAttribute[])
     */
@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
    if (attrs.length > 0) {
        throw new UnsupportedOperationException("Setting 'attrs' atomically is unsupported.");
    }
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
    MCRDirectory rootDirectory;
    if (mcrPath.isAbsolute() && mcrPath.getNameCount() == 0) {
        rootDirectory = MCRDirectory.getDirectory(mcrPath.getOwner());
        if (rootDirectory != null) {
            throw new FileAlreadyExistsException(mcrPath.toString());
        }
        rootDirectory = new MCRDirectory(mcrPath.getOwner());
        return;
    }
    rootDirectory = getRootDirectory(mcrPath);
    MCRPath parentPath = mcrPath.getParent();
    MCRPath absolutePath = getAbsolutePathFromRootComponent(parentPath);
    MCRFilesystemNode childByPath = rootDirectory.getChildByPath(absolutePath.toString());
    if (childByPath == null) {
        throw new NoSuchFileException(parentPath.toString(), dir.getFileName().toString(), "parent directory does not exist");
    }
    if (childByPath instanceof MCRFile) {
        throw new NotDirectoryException(parentPath.toString());
    }
    MCRDirectory parentDir = (MCRDirectory) childByPath;
    String dirName = mcrPath.getFileName().toString();
    if (parentDir.getChild(dirName) != null) {
        throw new FileAlreadyExistsException(mcrPath.toString());
    }
    new MCRDirectory(dirName, parentDir);
}
Also used : MCRFile(org.mycore.datamodel.ifs.MCRFile) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) NotDirectoryException(java.nio.file.NotDirectoryException) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) NoSuchFileException(java.nio.file.NoSuchFileException) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 60 with MCRPath

use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.

the class MCRFileSystemProvider method readAttributes.

/* (non-Javadoc)
     * @see java.nio.file.spi.FileSystemProvider#readAttributes(java.nio.file.Path, java.lang.String, java.nio.file.LinkOption[])
     */
@Override
public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException {
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(path);
    String[] s = splitAttrName(attributes);
    if (s[0].length() == 0) {
        throw new IllegalArgumentException(attributes);
    }
    BasicFileAttributeViewImpl view = null;
    switch(s[0]) {
        case "basic":
            view = new BasicFileAttributeViewImpl(mcrPath);
            break;
        case "md5":
            view = new MD5FileAttributeViewImpl(mcrPath);
            break;
    }
    if (view == null) {
        throw new UnsupportedOperationException("View '" + s[0] + "' not available");
    }
    return view.getAttributeMap(s[1].split(","));
}
Also used : MCRPath(org.mycore.datamodel.niofs.MCRPath)

Aggregations

MCRPath (org.mycore.datamodel.niofs.MCRPath)96 IOException (java.io.IOException)49 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)26 Path (java.nio.file.Path)25 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)22 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)22 Document (org.jdom2.Document)15 JDOMException (org.jdom2.JDOMException)15 MCRPersistenceException (org.mycore.common.MCRPersistenceException)14 MCRException (org.mycore.common.MCRException)13 MCRDirectory (org.mycore.datamodel.ifs.MCRDirectory)13 MCRAccessException (org.mycore.access.MCRAccessException)12 Files (java.nio.file.Files)11 Collectors (java.util.stream.Collectors)11 LogManager (org.apache.logging.log4j.LogManager)11 Logger (org.apache.logging.log4j.Logger)11 FileVisitResult (java.nio.file.FileVisitResult)10 NoSuchFileException (java.nio.file.NoSuchFileException)10 Date (java.util.Date)10 List (java.util.List)10