/** * Returns whether or not an OriginalFile exists on disk. * * @param file The original file metadata. * @return See above. */ public boolean exists(OriginalFile file) { String path = getFilesPath(file.getId()); return new File(path).exists(); } }
/** * Removes files from data repository based on a parameterized List of * Long file ids * * @param fileIds - Long file keys to be deleted * @throws ResourceError If deletion fails. */ public void removeFiles(List<Long> fileIds){ File file; boolean success = false; for (Iterator<Long> iter = fileIds.iterator(); iter.hasNext();) { Long id = iter.next(); String filePath = getFilesPath(id); file = new File(filePath); if (file.exists()) { success = file.delete(); if (!success) { throw new ResourceError("File " + file.getName() + " deletion failed"); } else { if (log.isInfoEnabled()) { log.info("INFO: File " + file.getName() + " deleted."); } } } } }
/** * Returns FileBuffer based on OriginalFile path * * @param file * @return FileBuffer */ public FileBuffer getFileBuffer(OriginalFile file, String mode) { String path = getFilesPath(file.getId()); createSubpath(path); return new FileBuffer(path, mode); }
/** * Attempts to parse the given {@link OriginalFile}. If any of the * necessary components is null, then it will return an empty, but not null * {@link Iterable}. Also looks for the catch all parser under "*" * * @param file * Can be null. * @return will not be null. */ protected Iterable<Reader> parse(final OriginalFile file, final OriginalFilesService files, final Map<String, FileParser> parsers) { if (files != null && parsers != null) { if (file != null && file.getMimetype() != null) { String path = files.getFilesPath(file.getId()); String format = file.getMimetype(); FileParser parser = parsers.get(format); if (parser != null) { return parser.parse(new File(path)); } else { parser = parsers.get("*"); if (parser != null) { return parser.parse(new File(path)); } } } } return FileParser.EMPTY; } }
/** * TODO CACHING */ public String getFilePath(final OriginalFile file, Current __current) throws ServerError { String repo = getFileRepo(file); if (repo != null) { throw new omero.ValidationException(null, null, "Does not belong to this repository"); } return fs.getFilesPath(file.getId().getValue()); }
targetFile = new File(filesService.getFilesPath(source.getId()));
/** * Detects if the given annotation contains an OMERO.table and if so, passes * it off for further processing. */ protected void handleAnnotation(Annotation annotation, RowProcessor proc) { annotation = getProxiedObject(annotation); if (annotation instanceof FileAnnotation) { final OriginalFile file = ((FileAnnotation) annotation).getFile(); final String mimetype = file.getMimetype(); final String path = ofs.getFilesPath(file.getId()); // ///////////////////////////////////////////////// if (OMERO_TABLE.equals(mimetype)) { debug("Handling annotation %s", annotation); handleHdf5(path, proc); } // ////////////////////////////////////////////////// } }