@Override public Object create(Map<String, Object> value) { String mimeType = (String) value.get("mime-type"); String encoding = (String) value.get("encoding"); // long length = -1; // Long lengthVal = (Long)value.get("length"); // if (lengthVal != null) { // length = lengthVal.longValue(); // } String filename = (String) value.get("name"); String digest = (String) value.get("digest"); Object data = value.get("data"); StreamSource ss; if (data instanceof String) { ss = new StringSource((String) data); } else if (data instanceof InputStream) { ss = new InputStreamSource((InputStream) data); } else if (data instanceof byte[]) { ss = new ByteArraySource((byte[]) data); } else { ss = new ByteArraySource(new byte[0]); } Blob blob = new StreamingBlob(ss); blob.setMimeType(mimeType); blob.setEncoding(encoding); blob.setFilename(filename); blob.setDigest(digest); return blob; }
@Override public Blob getBlob(String uri) throws PropertyException { String localPath = getLocalName(uri); String path = getFileAbsolutePath(localPath); File file = new File(path); if (!file.exists()) { throw new PropertyException(String.format("Cannot find file at '%s'", path)); } Blob blob = new FileBlob(file); blob.setFilename(file.getName()); return blob; }