Search in sources :

Example 1 with ContentPointer

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);
}
Also used : ContentPointer(v7db.files.spi.ContentPointer)

Example 2 with ContentPointer

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ContentPointer(v7db.files.spi.ContentPointer)

Example 3 with ContentPointer

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()));
}
Also used : MongoContentStorage(v7db.files.mongodb.MongoContentStorage) MongoContentStorage(v7db.files.mongodb.MongoContentStorage) ContentStorage(v7db.files.spi.ContentStorage) ContentPointer(v7db.files.spi.ContentPointer)

Example 4 with ContentPointer

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);
}
Also used : ContentPointer(v7db.files.spi.ContentPointer) BSONObject(org.bson.BSONObject) BasicDBObject(com.mongodb.BasicDBObject) BSONObject(org.bson.BSONObject) DBObject(com.mongodb.DBObject)

Example 5 with ContentPointer

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();
}
Also used : Mongo(com.mongodb.Mongo) ByteArrayInputStream(java.io.ByteArrayInputStream) ContentStorage(v7db.files.spi.ContentStorage) Content(v7db.files.spi.Content) ContentPointer(v7db.files.spi.ContentPointer)

Aggregations

ContentPointer (v7db.files.spi.ContentPointer)12 BasicDBObject (com.mongodb.BasicDBObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 BSONObject (org.bson.BSONObject)4 ContentStorage (v7db.files.spi.ContentStorage)4 DBObject (com.mongodb.DBObject)3 Mongo (com.mongodb.Mongo)3 ContentSHA (v7db.files.spi.ContentSHA)3 BasicBSONObject (org.bson.BasicBSONObject)2 MongoContentStorage (v7db.files.mongodb.MongoContentStorage)2 InlineContent (v7db.files.spi.InlineContent)2 DBCollection (com.mongodb.DBCollection)1 DBRef (com.mongodb.DBRef)1 WriteResult (com.mongodb.WriteResult)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Content (v7db.files.spi.Content)1 ReferenceTracking (v7db.files.spi.ReferenceTracking)1 StoredContent (v7db.files.spi.StoredContent)1