use of v7db.files.spi.StorageScheme in project v7files by thiloplanz.
the class MongoContentStorage method getContent.
@SuppressWarnings("unchecked")
private Content getContent(BSONObject data) throws IOException {
if (data == null)
return null;
data.removeField("_id");
String store = BSONUtils.getString(data, "store");
if (store == null || "raw".equals(store)) {
return InlineContent.deserialize(data.toMap());
}
StorageScheme s = storageSchemes.get(store);
if (s != null)
return s.getContent(this, data.toMap());
throw new UnsupportedOperationException(store);
}
use of v7db.files.spi.StorageScheme in project v7files by thiloplanz.
the class MongoContentStorage method getContent.
/**
* Supported formats: 1) Serialized ContentPointers, e.g.
*
* <pre>
* { in: [bytes] }
* </pre>
*
* and
*
* <pre>
* { sha: <sha>, length: 123 }
* </pre>
*
* 2) Internal StorageScheme representations (must have {store: something}")
*/
public Content getContent(Map<String, Object> data) throws IOException {
if (data == null)
return null;
String store = MapUtils.getString(data, "store");
if (store == null || "raw".equals(store)) {
if (data.containsKey("in"))
return InlineContent.deserialize(data);
if (data.containsKey("sha")) {
return new StoredContent((byte[]) data.get("sha"), MapUtils.getRequiredLong(data, "length")).loadOrLazyLoad(this, 8 * 1024);
}
throw new UnsupportedOperationException(data.toString());
}
StorageScheme s = storageSchemes.get(store);
if (s == null)
throw new UnsupportedOperationException(store);
return s.getContent(this, data);
}
use of v7db.files.spi.StorageScheme in project v7files by thiloplanz.
the class MongoContentStorage method storeContent.
public ContentPointer storeContent(Map<String, Object> storageScheme) throws IOException {
StorageScheme s = storageSchemes.get(storageScheme.get("store"));
if (s == null)
throw new UnsupportedOperationException(storageScheme.toString());
DBObject x = new BasicDBObject();
for (Map.Entry<String, Object> e : storageScheme.entrySet()) {
x.put(e.getKey(), e.getValue());
}
long length = BSONUtils.getRequiredLong(x, "length");
byte[] sha = DigestUtils.sha(s.getContent(this, storageScheme).getInputStream());
long existing = contentCollection.count(new BasicDBObject(_ID, sha));
if (existing == 0) {
x.put(_ID, sha);
contentCollection.insert(x, WriteConcern.SAFE);
}
return new StoredContent(sha, length);
}
Aggregations