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;
}
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;
}
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;
}
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);
}
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)));
}
Aggregations