@Override public File getFile() { return blob.getFile(); }
/** * Gets a new blob on a temporary file which is a copy of the blob's. * * @since 7.4 */ protected Blob getTemporaryBlob(Blob blob) throws IOException { String ext = FilenameUtils.getExtension(blob.getFilename()); if (!VALID_EXT.matcher(ext).matches()) { ext = "tmp"; } Blob newBlob = new FileBlob('.' + ext); File tmp = newBlob.getFile(); File file = blob.getFile(); if (file == null) { try (InputStream in = blob.getStream()) { Files.copy(in, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING); } } else { // do a copy Files.copy(file.toPath(), tmp.toPath(), StandardCopyOption.REPLACE_EXISTING); } return newBlob; }
@Override public Map<String, String> setupParameters(BlobHolder input, Map<String, Object> parameters) { Map<String, String> cmdParameters = super.setupParameters(input,parameters); Blob video = input.getBlob(); String x = (String) parameters.get(WATERMARK_X_POSITION_PARAM); String y = (String) parameters.get(WATERMARK_Y_POSITION_PARAM); Blob watermark = (Blob) parameters.get(WATERMARK_PARAM); // Prepare parameters try { String overlay = "overlay=" + x + ":" + y; File outputFile = Framework.createTempFile(FilenameUtils.removeExtension(video.getFilename()), "-WM." + FilenameUtils.getExtension(video.getFilename())); cmdParameters.put(WATERMARK_PARAM, watermark.getFile().getAbsolutePath()); cmdParameters.put(FILTER_COMPLEX_PARAM, overlay); cmdParameters.put(OUTPUT_FILE_PATH_PARAM, outputFile.getAbsolutePath()); } catch (IOException e) { throw new NuxeoException("Cannot setup parameters for VideoWatermarker.", e); } return cmdParameters; } }
public File getFile() { return blob.getFile(); }
/** * We don't want to rely on {@link Blob#getCloseableFile} because it may return the original and we always want a * temporary one to be sure we have a clean filename to pass. * * @since 7.4 */ protected CloseableFile getTemporaryFile(Blob blob) throws IOException { String ext = FilenameUtils.getExtension(blob.getFilename()); if (!VALID_EXT.matcher(ext).matches()) { ext = "tmp"; } File tmp = Framework.createTempFile("nxblob-", '.' + ext); File file = blob.getFile(); if (file == null) { // if we don't have an underlying File, use a temporary File try (InputStream in = blob.getStream()) { Files.copy(in, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING); } } else { // attempt to create a symbolic link, which would be cheaper than a copy tmp.delete(); try { Files.createSymbolicLink(tmp.toPath(), file.toPath().toAbsolutePath()); } catch (IOException | UnsupportedOperationException e) { // symbolic link not supported, do a copy instead Files.copy(file.toPath(), tmp.toPath()); } } return new CloseableFile(tmp, true); }
/** * If the blob is backed by an actual file, return it. * <p> * Note that the File may be short-lived (temporary file), so should be used immediately. * * @return a File, or {@code null} if this blob doesn't have one * @deprecated since 7.2, use {@link Blob#getFile} directly */ @Deprecated public static File getFileFromBlob(Blob blob) { return blob.getFile(); }
File blobFile = b.getFile(); sourceFiles.add(blobFile); lines.add("file '" + blobFile.getAbsolutePath());
public Map<String, String> setupParameters(BlobHolder input, Map<String, Object> parameters) { Map<String, String> cmdParameters = new HashMap<>(); cmdParameters.put(SOURCE_FILE_PATH_PARAM, input.getBlob().getFile().getAbsolutePath()); return cmdParameters; }
try { String password = (StringUtils.isBlank(originalOwnerPwd)) ? ownerPwd : originalOwnerPwd; pdfDoc = PDDocument.load(pdfBlob.getFile()); if (!pdfDoc.isEncrypted()) { pdfDoc.close(); pdfDoc.setAllSecurityToBeRemoved(true); Blob result = Blobs.createBlobWithExtension(".pdf"); pdfDoc.save(result.getFile()); result.setMimeType("application/pdf"); if (StringUtils.isNotBlank(pdfBlob.getFilename())) { FileBlob fb = new FileBlob(result.getFile()); fb.setMimeType("application/pdf"); return fb;
protected Blob sort(Blob blob, String commandId) { try { Path temp = createTemp("tmp" + commandId); ExternalSort.sort(blob.getFile(), temp.toFile()); return new FileBlob(temp.toFile()); } catch (IOException e) { log.error("Unable to sort blob", e); return blob; } }
Blob newBlob = getTemporaryBlob(blob); CmdParameters params = commandLineService.getDefaultCmdParameters(); params.addNamedParameter("inFilePath", newBlob.getFile()); params.addNamedParameter("tagList", getCommandTags(metadata)); ExecResult er = commandLineService.execCommand(command, params);
private Blob createBlob(ZipEntry entry) throws IOException { if (zipFile != null) { return new ZipEntryBlob(zipFile, entry); } else { // should decompress since this is a generic stream // FileBlob always closes the stream, but we don't want that // so wrap it in a CloseShieldInputStream try (CloseShieldInputStream ncin = new CloseShieldInputStream(in)) { Blob blob = Blobs.createBlob(ncin); filesToDelete.add(blob.getFile()); return blob; } } }
/** * Gets a temporary blob for the given temporary path. * <p> * The temporary blob is backed by a temporary file in a new location. The old file is removed. * * @param path the path to a temporary file * @param mimeType the blob MIME type * @return a temporary {@link Blob} */ public static Blob getTemporaryBlob(String path, String mimeType) { String ext = "." + FilenameUtils.getExtension(path); Blob blob; try { blob = new FileBlob(ext); // automatically tracked for removal Files.move(Paths.get(path), blob.getFile().toPath(), REPLACE_EXISTING); } catch (IOException e) { throw new NuxeoException(e); } blob.setMimeType(mimeType); blob.setFilename(FilenameUtils.getName(path)); return blob; }
public static FileBlob saveInTempFile(PDDocument inPdfDoc, String inFileName) throws IOException, COSVisitorException { Blob result = Blobs.createBlobWithExtension(".pdf"); File resultFile = result.getFile(); inPdfDoc.save(result.getFile()); result.setMimeType("application/pdf"); if (StringUtils.isNotBlank(inFileName)) { result.setFilename(inFileName); } FileBlob fb = new FileBlob(resultFile); fb.setMimeType("application/pdf"); return fb; }
protected Blob saveInTempFile(PDDocument PdfDoc) throws IOException, COSVisitorException { Blob blob = Blobs.createBlobWithExtension(".pdf"); // creates a tracked temporary file blob.setMimeType(MIME_TYPE); PdfDoc.save(blob.getFile()); return blob; }
@Override public Calendar getModificationDate() { if (isStored()) { DocumentModel hdoc = getHostDocument(); if (hdoc != null) { try { return (Calendar) hdoc.getPropertyValue("dc:modified"); } catch (PropertyException e) { log.error(e); } } } else if (isCompleted()) { Calendar cal = Calendar.getInstance(); Blob blob = getBlob(); if (blob != null) { File file = blob.getFile(); if (file != null) { cal.setTimeInMillis(file.lastModified()); } } return cal; } return null; }
@Override public Binary getBinary(Blob blob) throws IOException { if (!(blob instanceof FileBlob)) { return super.getBinary(blob); // just open the stream and call getBinary(InputStream) } // we already have a file so can compute the length and digest efficiently File file = blob.getFile(); String digest; try (InputStream in = new FileInputStream(file)) { digest = DigestUtils.md5Hex(in); } // if the digest is not already known then save to GridFS GridFSFile dbFile = gridFSBucket.find(Filters.eq(METADATA_PROPERTY_FILENAME, digest)).first(); if (dbFile == null) { try (InputStream in = new FileInputStream(file)) { gridFSBucket.uploadFromStream(digest, in); } } return new GridFSBinary(digest, blobProviderId); }
public static void export(List<DocumentModel> docList) { DocumentReader reader = null; DocumentWriter writer = null; Blob blob = null; try { reader = new DocumentModelListReader(docList); blob = Blobs.createBlobWithExtension("zip"); writer = new NuxeoArchiveWriter(blob.getFile()); DocumentPipe pipe = new DocumentPipeImpl(10); pipe.setReader(reader); pipe.setWriter(writer); pipe.run(); } catch (IOException e) { log.error("Error during XML export " + e.getMessage()); } finally { if (reader != null) { reader.close(); } if (writer != null) { writer.close(); } } if (blob != null) { ComponentUtils.download(null, null, blob, "export.zip", "workListXML"); if (blob.getFile() != null) { blob.getFile().delete(); } } }
@Override public String exportWorklistAsZip(List<DocumentModel> documents, boolean exportAllBlobs) { Blob blob = null; try { DownloadService downloadService = Framework.getService(DownloadService.class); DocumentListZipExporter zipExporter = new DocumentListZipExporter(); blob = zipExporter.exportWorklistAsZip(documents, documentManager, exportAllBlobs); if (blob == null) { // empty zip file, do nothing facesMessages.add(StatusMessage.Severity.INFO, messages.get("label.clipboard.emptyDocuments")); return null; } blob.setMimeType("application/zip"); blob.setFilename("clipboard.zip"); String key = downloadService.storeBlobs(Collections.singletonList(blob)); String url = BaseURL.getBaseURL() + downloadService.getDownloadUrl(key); ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); context.redirect(url); return ""; } catch (IOException io) { if (blob != null) { blob.getFile().delete(); } throw new NuxeoException("Error while redirecting for clipboard content", io); } } }
protected Blob getBlob(FileItem item) { try { Blob blob; if (item.isInMemory()) { blob = Blobs.createBlob(item.get()); } else { File file; if (item instanceof DiskFileItem // && (file = ((DiskFileItem) item).getStoreLocation()) != null) { // move the file to a temporary blob we own blob = Blobs.createBlobWithExtension(null); Files.move(file.toPath(), blob.getFile().toPath(), REPLACE_EXISTING); } else { // if we couldn't get to the file, use the InputStream try (InputStream in = item.getInputStream()) { blob = Blobs.createBlob(in); } } } blob.setMimeType(defaultIfEmpty(item.getContentType(), "application/octet-stream")); blob.setFilename(item.getName()); return blob; } catch (IOException e) { throw new NuxeoException("Failed to get blob data", e); } }