use of v7db.files.spi.ContentPointer in project v7files by thiloplanz.
the class ContentStorageFacade method insertContentsAndBackRefs.
/**
* will close the InputStream before returning
*/
public BSONObject insertContentsAndBackRefs(InputStream data, Object fileId, String filename, String contentType) throws IOException {
if (data == null)
return insertContentsAndBackRefs(null, 0, 0, fileId, filename, contentType);
ContentPointer p = storage.storeContent(data);
refTracking.updateReferences(fileId, p);
return makeMetaData(filename, contentType, p);
}
use of v7db.files.spi.ContentPointer in project v7files by thiloplanz.
the class ContentStorageFacade method insertContentsAndBackRefs.
public BSONObject insertContentsAndBackRefs(byte[] data, int offset, int len, Object fileId, String filename, String contentType) throws IOException {
if (data == null) {
refTracking.updateReferences(fileId);
return makeMetaData(filename, contentType, null);
}
ContentPointer p = storage.storeContent(new ByteArrayInputStream(data, offset, len));
refTracking.updateReferences(fileId, p);
return makeMetaData(filename, contentType, p);
}
use of v7db.files.spi.ContentPointer in project v7files by thiloplanz.
the class ZipFileTest method testPullOutFileFromZip.
public void testPullOutFileFromZip() throws MongoException, IOException, ZipException, DecoderException {
ContentStorage storage = new MongoContentStorage(getMongo().getDB("test"));
ContentPointer zip = storage.storeContent(getClass().getResourceAsStream("mongodb.epub"));
ContentPointer png = ZipFile.extractFile(storage, zip, "images/img0.png");
assertEquals("fc012bb0439382f709d3caebab958ff592811d17", DigestUtils.shaHex(storage.getContent(png).getInputStream()));
}
use of v7db.files.spi.ContentPointer in project v7files by thiloplanz.
the class V7GridFS method updateContents.
void updateContents(DBObject metaData, ContentPointer newContents) throws IOException {
ContentPointer oldContents = getContentPointer(metaData);
if (newContents.contentEquals(oldContents))
return;
String filename = (String) metaData.get("filename");
String contentType = (String) metaData.get("contentType");
Object fileId = metaData.get("_id");
BSONObject newContent = storage.updateBackRefs(newContents, fileId, filename, contentType);
metaData.removeField("sha");
metaData.removeField("length");
metaData.removeField("in");
metaData.putAll(newContent);
updateMetaData(metaData);
}
use of v7db.files.spi.ContentPointer in project v7files by thiloplanz.
the class MongoContentStorageTest method testRoundtrip.
public void testRoundtrip() throws MongoException, IOException {
Mongo mongo = getMongo();
ContentStorage storage = new MongoContentStorage(mongo.getDB("test").getCollection("v7files.content"));
byte[] data = "abcdefghijklmnopqrstuvwxyz".getBytes();
ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(data));
Content check = storage.getContent(pointer);
assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
assertEquals(data.length, check.getLength());
mongo.close();
}
Aggregations