Search in sources :

Example 1 with MCRAbstractFileStore

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

the class MCRIView2Tools method getFilePath.

public static String getFilePath(String derID, String derPath) throws IOException {
    MCRPath mcrPath = MCRPath.getPath(derID, derPath);
    Path physicalPath = mcrPath.toPhysicalPath();
    for (FileStore fs : mcrPath.getFileSystem().getFileStores()) {
        if (fs instanceof MCRAbstractFileStore) {
            Path basePath = ((MCRAbstractFileStore) fs).getBaseDirectory();
            if (physicalPath.startsWith(basePath)) {
                return basePath.relativize(physicalPath).toString();
            }
        }
    }
    return physicalPath.toString();
}
Also used : Path(java.nio.file.Path) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRAbstractFileStore(org.mycore.datamodel.niofs.MCRAbstractFileStore) FileStore(java.nio.file.FileStore) MCRAbstractFileStore(org.mycore.datamodel.niofs.MCRAbstractFileStore) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 2 with MCRAbstractFileStore

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

the class MCRMediaSourceProvider method getContentPath.

private static String getContentPath(String derivateId, String path) {
    try {
        MCRPath mcrPath = MCRPath.getPath(derivateId, path);
        MCRAbstractFileStore fileStore = (MCRAbstractFileStore) Files.getFileStore(mcrPath);
        java.nio.file.Path absolutePath = fileStore.getPhysicalPath(mcrPath);
        java.nio.file.Path relativePath = fileStore.getBaseDirectory().relativize(absolutePath);
        LogManager.getLogger().info("{} -> {} -> {}", mcrPath, absolutePath, relativePath);
        return relativePath.toString();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : MCRAbstractFileStore(org.mycore.datamodel.niofs.MCRAbstractFileStore) IOException(java.io.IOException) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Aggregations

MCRAbstractFileStore (org.mycore.datamodel.niofs.MCRAbstractFileStore)2 MCRPath (org.mycore.datamodel.niofs.MCRPath)2 IOException (java.io.IOException)1 FileStore (java.nio.file.FileStore)1 Path (java.nio.file.Path)1