/** * Zip a list of blob. * * @param blobs the blob list * @param fileName if no filename is given, the first blob's filename will be used * @return a zip containing the list of blob * @throws IOException */ public static Blob zip(List<Blob> blobs, String fileName) throws IOException { if (fileName == null || (fileName = fileName.trim()).length() == 0) { fileName = blobs.isEmpty() ? null : blobs.get(0).getFilename(); } File file = Framework.createTempFile("nxops-createzip-", ".tmp"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file)); Framework.trackFile(file, file); try { zip(blobs, out); } finally { out.finish(); out.close(); } return Blobs.createBlob(file, "application/zip", null, fileName); }
/** * Zip the given blob. * * @param blob the blob * @param filename if no filename is given, the blob's filename will be used * @return a zip containing the blob * @throws IOException */ public static Blob zip(Blob blob, String filename) throws IOException { if (filename == null || (filename = filename.trim()).length() == 0) { filename = blob.getFilename(); } File file = Framework.createTempFile("nxops-createzip-", ".tmp"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file)); Framework.trackFile(file, file); try { zip(blob, out); } finally { out.finish(); out.close(); } return Blobs.createBlob(file, "application/zip", null, filename); }
@OperationMethod public Blob run(Blob blob) throws IOException { return BlobUtils.zip(blob, fileName); }
@OperationMethod public Blob run(BlobList blobs) throws IOException { return BlobUtils.zip(blobs, fileName); }
@OperationMethod public Blob run(DocumentModelList docs) throws IOException { DownloadService downloadService = Framework.getService(DownloadService.class); List<Blob> blobs = docs.stream().map(doc -> { Blob blob = downloadService.resolveBlob(doc); if (blob == null) { log.trace("Not able to resolve blob"); return null; } if (!downloadService.checkPermission(doc, null, blob, "download", Collections.emptyMap())) { log.debug("Not allowed to bulk download blob for document {}", doc::getPathAsString); return null; } return blob; }).filter(Objects::nonNull).collect(Collectors.toList()); if (blobs.isEmpty()) { log.debug("No blob to be zipped"); return null; } String filename = StringUtils.isNotBlank(this.fileName) ? this.fileName : String.format("BlobListZip-%s-%s", UUID.randomUUID(), session.getPrincipal().getName()); return BlobUtils.zip(blobs, filename); }
String finalFilename = StringUtils.isNotBlank(this.filename) ? this.filename : this.id; try { blob = BlobUtils.zip(blobList, finalFilename); } catch (IOException e) { TransientStore ts = getTransientStore();
@Override public void processRecord(ComputationContext context, String inputStreamName, Record record) { Codec<DataBucket> codec = BulkCodecs.getDataBucketCodec(); DataBucket in = codec.decode(record.getData()); String storeName = Framework.getService(BulkService.class).getStatus(in.getCommandId()).getAction(); Blob blob = getBlob(in.getDataAsString(), storeName); try { blob = BlobUtils.zip(blob, blob.getFilename() + ".zip"); } catch (IOException e) { log.error("Unable to zip blob", e); } storeBlob(blob, in.getCommandId(), storeName); DataBucket out = new DataBucket(in.getCommandId(), in.getCount(), getTransientStoreKey(in.getCommandId())); context.produceRecord(OUTPUT_1, Record.of(in.getCommandId(), codec.encode(out))); context.askForCheckpoint(); }