/** * Returns a {@link RenderBinary} result with an {@link ISObject} instance. The result will render * the binary using "attachment" content disposition * * @param sobj * the {@link ISObject} instance */ public static RenderBinary download(ISObject sobj) { return new RenderBinary(sobj.asInputStream(), sobj.getAttribute(ISObject.ATTR_FILE_NAME), sobj.getAttribute(ISObject.ATTR_CONTENT_TYPE), false); }
@Override public byte[] asByteArray() throws UnexpectedIOException { return sobj.asByteArray(); }
@Override public File asFile() throws UnexpectedIOException { return sobj.asFile(); }
public InputStream forceGet() { if (sobj.isEmpty()) { sobj = ss.forceGet(sobj.getKey()); } return sobj.asInputStream(); }
@Override public String toString() { return S.fmt("BLOB://[%s]/%s", sobj.getKey(), sobj.getAttribute(FILENAME)); }
@Override protected InputStream load() { return source.asInputStream(); } }
@Override protected void doPut(String fullPath, ISObject stuff, Map<String, String> attrs) { ObjectMetadata meta = new ObjectMetadata(); meta.setContentType(stuff.getAttribute(ISObject.ATTR_CONTENT_TYPE)); if (!(stuff instanceof SObject.InputStreamSObject)) { long length = stuff.getLength(); if (0 < length) { meta.setContentLength(stuff.getLength()); } } PutObjectRequest req = new PutObjectRequest(bucket, fullPath, stuff.asInputStream(), meta); req.setTagging(mapToTagList(attrs)); StorageClass storageClass = StorageClass.valueOfIgnoreCase(attrs.remove(ATTR_STORAGE_CLASS), defStorageClass); if (null != storageClass) { req.setStorageClass(storageClass.toString()); } req.withCannedAcl(CannedAccessControlList.PublicRead); s3.putObject(req); }
bp.setText(content, config().encoding(), accept().name()); for (ISObject sobj : attachments) { String fileName = sobj.getAttribute(ISObject.ATTR_FILE_NAME); if (S.blank(fileName)) { fileName = sobj.getKey(); String contentType = sobj.getAttribute(ISObject.ATTR_CONTENT_TYPE); if (S.blank(contentType)) { contentType = "application/octet-stream"; attachment.attachFile(sobj.asFile(), contentType, null); attachment.setFileName(fileName); mp.addBodyPart(attachment);
@Override public ISObject put(String key, ISObject stuff) { String processedKey = key; if (storeSuffix) { String originalFilename = stuff.getAttribute(ISObject.ATTR_FILE_NAME); if (null != originalFilename) { String suffix = S.afterLast(originalFilename, "."); if (S.notBlank(suffix)) { suffix = S.concat(".", suffix); if (!key.endsWith(suffix)) { processedKey = S.concat(key, suffix); } } } } if ((S.eq(key, stuff.getKey()) || S.eq(processedKey, stuff.getKey()) && isManagedObject(stuff))) { return stuff; } Map<String, String> attrs = stuff.getAttributes(); removeRuntimeAttributes(attrs); if (!(stuff instanceof SObject.InputStreamSObject)) { long len = stuff.getLength(); if (0L < len) { attrs.put(ISObject.ATTR_CONTENT_LENGTH, S.string(len)); } } doPut(keyWithContextPath(processedKey), stuff, attrs); return getFull(processedKey); }
@Override public String type() { return sobj.getAttribute(CONTENT_TYPE); }
@Override public String asString(Charset charset) throws UnexpectedIOException { return sobj.asString(charset); }
@Override protected void doPut(String fullPath, ISObject stuff, Map<String, String> attrs) { try { CloudBlockBlob blob = blobContainer.getBlockBlobReference(fullPath); if (!(stuff instanceof SObject.InputStreamSObject)) { blob.upload(stuff.asInputStream(), stuff.getLength()); } BlobProperties props = blob.getProperties(); // content-type contains "-" which is illegal character in C# identifier // so we have to remove it from meta map String contentType = attrs.remove(ISObject.ATTR_CONTENT_TYPE); if (S.notBlank(contentType)) { props.setContentType(contentType); } blob.uploadProperties(); blob.getMetadata().putAll(attrs); blob.uploadMetadata(); } catch (Exception e) { throw E.unexpected(e); } }
@Override public void put(String key, ISObject stuff) throws UnexpectedIOException { GridFS gfs = gfs(); gfs.remove(new BasicDBObject("name", key)); GridFSInputFile inputFile = gfs.createFile(stuff.asByteArray()); inputFile.setContentType(stuff.getAttribute(Blob.CONTENT_TYPE)); inputFile.put("name", key); inputFile.put("filename", stuff.getAttribute(Blob.FILENAME)); inputFile.save(); }
@Override public String getAttribute(String key) { return sobj.getKey(); }
public static SObject valueOf(String key, ISObject copy) { SObject sobj = of(key, copy.asByteArray()); sobj.setAttrs(copy.getAttributes()); return sobj; }
@Override public long getLength() { return null == sobj_ ? -1 : sobj_.getLength(); }
private void setDefAttributes(ISObject sobj) { Map<String, String> map = C.newMap(); setDefAttributes(sobj.getKey(), map); sobj.setAttributes(map); }
@Override public Map<String, String> getAttributes() { return sobj.getAttributes(); }
@Override protected InputStream load() { return source.asInputStream(); } }