Search in sources :

Example 16 with MCRPath

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

the class MCRUploadHandlerIFS method acceptFile.

@Override
public boolean acceptFile(String path, String checksum, long length) throws Exception {
    LOGGER.debug("incoming acceptFile request: {} {} {} bytes", path, checksum, length);
    boolean shouldAcceptFile = true;
    if (rootDir != null) {
        MCRPath child = MCRPath.toMCRPath(rootDir.resolve(path));
        if (Files.isRegularFile(child)) {
            @SuppressWarnings("rawtypes") MCRFileAttributes attrs = Files.readAttributes(child, MCRFileAttributes.class);
            shouldAcceptFile = attrs.size() != length || !(checksum.equals(attrs.md5sum()) && child.getFileSystem().verifies(child, attrs));
        }
    }
    LOGGER.debug("Should the client send this file? {}", shouldAcceptFile);
    return shouldAcceptFile;
}
Also used : MCRFileAttributes(org.mycore.datamodel.niofs.MCRFileAttributes) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 17 with MCRPath

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

the class MCRUploadHandlerIFS method getFile.

private MCRPath getFile(String path) throws IOException {
    MCRPath pathToFile = MCRPath.toMCRPath(rootDir.resolve(path));
    MCRPath parentDirectory = pathToFile.getParent();
    if (!Files.isDirectory(parentDirectory)) {
        Files.createDirectories(parentDirectory);
    }
    return pathToFile;
}
Also used : MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 18 with MCRPath

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

the class MCRBasketPersistence method retrieveBasket.

/**
 * Retrieves a basket from an XML file in the given derivate.
 */
public static MCRBasket retrieveBasket(String derivateID) throws Exception {
    MCRPath file = getBasketFile(derivateID);
    Document xml = new MCRPathContent(file).asXML();
    MCRBasket basket = new MCRBasketXMLParser().parseXML(xml);
    basket.setDerivateID(derivateID);
    return basket;
}
Also used : MCRPathContent(org.mycore.common.content.MCRPathContent) MCRPath(org.mycore.datamodel.niofs.MCRPath) Document(org.jdom2.Document)

Example 19 with MCRPath

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

the class MCRDirectoryStream method newByteChannel.

@Override
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
    checkClosed();
    MCRPath mcrPath = checkRelativePath(path);
    if (mcrPath.isAbsolute()) {
        return mcrPath.getFileSystem().provider().newByteChannel(mcrPath, options, attrs);
    }
    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);
        }
    }
    MCRFileSystemProvider provider = (MCRFileSystemProvider) mcrPath.getFileSystem().provider();
    MCRFileSystemUtils.getMCRFile(dir, mcrPath, create, createNew);
    return provider.newByteChannel(this.path.resolve(mcrPath), fileOpenOptions, attrs);
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) ClosedDirectoryStreamException(java.nio.file.ClosedDirectoryStreamException) MCRFileAttributes(org.mycore.datamodel.niofs.MCRFileAttributes) LinkOption(java.nio.file.LinkOption) InvalidPathException(java.nio.file.InvalidPathException) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRMD5AttributeView(org.mycore.datamodel.niofs.MCRMD5AttributeView) SecureDirectoryStream(java.nio.file.SecureDirectoryStream) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) NoSuchElementException(java.util.NoSuchElementException) Path(java.nio.file.Path) MCRFile(org.mycore.datamodel.ifs.MCRFile) Iterator(java.util.Iterator) Files(java.nio.file.Files) OpenOption(java.nio.file.OpenOption) MCRPath(org.mycore.datamodel.niofs.MCRPath) FileAttributeView(java.nio.file.attribute.FileAttributeView) MCRPersistenceException(org.mycore.common.MCRPersistenceException) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) IOException(java.io.IOException) FileAttribute(java.nio.file.attribute.FileAttribute) Collectors(java.util.stream.Collectors) DirectoryIteratorException(java.nio.file.DirectoryIteratorException) Objects(java.util.Objects) SeekableByteChannel(java.nio.channels.SeekableByteChannel) Logger(org.apache.logging.log4j.Logger) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) Optional(java.util.Optional) LogManager(org.apache.logging.log4j.LogManager) OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 20 with MCRPath

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

the class MCRDirectoryStream method newDirectoryStream.

@Override
public SecureDirectoryStream<Path> newDirectoryStream(Path path, LinkOption... options) throws IOException {
    checkClosed();
    MCRPath mcrPath = checkFileSystem(path);
    if (mcrPath.isAbsolute()) {
        return (SecureDirectoryStream<Path>) Files.newDirectoryStream(mcrPath);
    }
    MCRFilesystemNode childByPath = dir.getChildByPath(mcrPath.toString());
    if (childByPath == null || childByPath instanceof MCRFile) {
        throw new NoSuchFileException(dir.toString(), path.toString(), "Does not exist or is a file.");
    }
    return new MCRDirectoryStream((MCRDirectory) childByPath, MCRPath.toMCRPath(path.resolve(mcrPath)));
}
Also used : MCRFile(org.mycore.datamodel.ifs.MCRFile) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) NoSuchFileException(java.nio.file.NoSuchFileException) MCRPath(org.mycore.datamodel.niofs.MCRPath) SecureDirectoryStream(java.nio.file.SecureDirectoryStream)

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