use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRMailEventHandler method handlePathEvent.
private void handlePathEvent(MCREvent evt, Path file, BasicFileAttributes attrs) {
if (!(file instanceof MCRPath)) {
return;
}
MCRPath path = MCRPath.toMCRPath(file);
MCRContent xml;
try {
xml = new MCRJDOMContent(MCRPathXML.getFileXML(path, attrs));
handleEvent(evt, xml, path.toString());
} catch (IOException e) {
LOGGER.error("Error while generating mail for {}", file, e);
}
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRXMLFunctions method getSize.
/**
* Method returns the amount of space consumed by the files contained in the
* derivate container. The returned string is already formatted meaning it
* has already the optimal measurement unit attached (e.g. 142 MB, ).
*
* @param derivateId
* the derivate id for which the size should be returned
* @return the size as formatted string
*/
public static String getSize(String derivateId) throws IOException {
MCRPath rootPath = MCRPath.getPath(derivateId, "/");
final AtomicLong size = new AtomicLong();
Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
size.addAndGet(attrs.size());
return super.visitFile(file, attrs);
}
});
return MCRUtils.getSizeFormatted(size.get());
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRCompressServlet method sendDerivate.
private void sendDerivate(MCRObjectID id, String path, T container) throws IOException {
MCRPath resolvedPath = MCRPath.getPath(id.toString(), path == null ? "/" : path);
if (!Files.exists(resolvedPath)) {
throw new NoSuchFileException(id.toString(), path, "Could not find path " + resolvedPath);
}
if (Files.isRegularFile(resolvedPath)) {
BasicFileAttributes attrs = Files.readAttributes(resolvedPath, BasicFileAttributes.class);
sendCompressedFile(resolvedPath, attrs, container);
LOGGER.debug("file {} zipped", resolvedPath);
return;
}
// root is a directory
Files.walkFileTree(resolvedPath, new CompressVisitor<>(this, container));
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRIViewZipResource method zip.
/**
* Zips a derivate and its containing iview images as jpg's. All other files are ignored.
*
* @param derivateID the derivate to zip
* @param zoom if undefined the base resolution is assumed
* @return zip file
*/
@GET
@Produces("application/zip")
@Path("{derivateID}")
public Response zip(@PathParam("derivateID") String derivateID, @QueryParam("zoom") Integer zoom) throws Exception {
if (!MCRAccessManager.checkPermissionForReadingDerivate(derivateID)) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
MCRPath derivateRoot = MCRPath.getPath(derivateID, "/");
if (!Files.exists(derivateRoot)) {
throw new WebApplicationException(Status.NOT_FOUND);
}
ZipStreamingOutput stream = new ZipStreamingOutput(derivateRoot, zoom);
return Response.ok(stream).header("Content-Disposition", "attachnment; filename=\"" + derivateID + ".zip\"").build();
}
use of org.mycore.datamodel.niofs.MCRPath 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();
}
Aggregations